From 263d04d756321b3250d9ae700101f52d9663a2f0 Mon Sep 17 00:00:00 2001 From: tuncaulubilge Date: Sun, 18 Mar 2018 20:04:45 -0700 Subject: [PATCH] Added nestedScrollEnabled prop to scroll view for android Summary: Nested scrolling in scrollViews, listViews and flatLists are enabled on iOS by default, but needs to be enabled manually on Android. This PR introduces a `nestedScrollEnabled` property to ScrollViews to support nested scrolling on Android 21 and above. Enabling nested scroll will resolve issues with coordinator layout in android and required to support a collapsing toolbar. Tested on the test app. We are also using this property in our app currently to support scrolling behaviour required by coordinator layouts. [ANDROID] [ENHANCEMENT] [ScrollView] - Added a prop to enable nested scrolling Closes https://github.com/facebook/react-native/pull/18299 Reviewed By: sahrens Differential Revision: D7256604 Pulled By: mdvacca fbshipit-source-id: fb8b7f1b5bed39837a2066db7f2a8798d52a3fd6 --- Libraries/Components/ScrollView/ScrollView.js | 6 ++++++ .../views/scroll/ReactHorizontalScrollViewManager.java | 8 ++++++++ .../react/views/scroll/ReactScrollViewManager.java | 10 +++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 5d0d007fe..29b9d57ca 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -275,6 +275,12 @@ const ScrollView = createReactClass({ * @platform ios */ minimumZoomScale: PropTypes.number, + /** + * Enables nested scrolling for Android API level 21+. + * Nested scrolling is supported by default on iOS + * @platform android + */ + nestedScrollEnabled: PropTypes.bool, /** * Called when the momentum scroll starts (scroll which occurs as the ScrollView glides to a stop). */ diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java index f0d9a6011..e6536a6e5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollViewManager.java @@ -8,7 +8,9 @@ package com.facebook.react.views.scroll; import android.graphics.Color; +import android.support.v4.view.ViewCompat; import android.util.DisplayMetrics; + import com.facebook.react.bridge.ReadableArray; import com.facebook.react.module.annotations.ReactModule; import com.facebook.react.uimanager.DisplayMetricsHolder; @@ -21,6 +23,7 @@ import com.facebook.react.uimanager.ViewProps; import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.annotations.ReactPropGroup; import com.facebook.yoga.YogaConstants; + import javax.annotation.Nullable; /** @@ -120,6 +123,11 @@ public class ReactHorizontalScrollViewManager view.setOverScrollMode(ReactScrollViewHelper.parseOverScrollMode(value)); } + @ReactProp(name = "nestedScrollEnabled") + public void setNestedScrollEnabled(ReactHorizontalScrollView view, boolean value) { + ViewCompat.setNestedScrollingEnabled(view, value); + } + @Override public void receiveCommand( ReactHorizontalScrollView scrollView, diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java index ecab38a6d..df520b5e4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java @@ -9,6 +9,8 @@ package com.facebook.react.views.scroll; import android.annotation.TargetApi; import android.graphics.Color; +import android.support.v4.view.ViewCompat; + import com.facebook.react.bridge.ReadableArray; import com.facebook.react.common.MapBuilder; import com.facebook.react.module.annotations.ReactModule; @@ -21,8 +23,9 @@ import com.facebook.react.uimanager.ViewProps; import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.annotations.ReactPropGroup; import com.facebook.yoga.YogaConstants; -import java.util.Map; + import javax.annotation.Nullable; +import java.util.Map; /** * View manager for {@link ReactScrollView} components. @@ -121,6 +124,11 @@ public class ReactScrollViewManager view.setOverScrollMode(ReactScrollViewHelper.parseOverScrollMode(value)); } + @ReactProp(name = "nestedScrollEnabled") + public void setNestedScrollEnabled(ReactScrollView view, boolean value) { + ViewCompat.setNestedScrollingEnabled(view, value); + } + @Override public @Nullable Map getCommandsMap() { return ReactScrollViewCommandHelper.getCommandsMap();