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
This commit is contained in:
tuncaulubilge 2018-03-18 20:04:45 -07:00 committed by Facebook Github Bot
parent 378da73201
commit 263d04d756
3 changed files with 23 additions and 1 deletions

View File

@ -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).
*/

View File

@ -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,

View File

@ -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<String, Integer> getCommandsMap() {
return ReactScrollViewCommandHelper.getCommandsMap();