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 коммит произвёл Facebook Github Bot
Родитель 378da73201
Коммит 263d04d756
3 изменённых файлов: 23 добавлений и 1 удалений

Просмотреть файл

@ -275,6 +275,12 @@ const ScrollView = createReactClass({
* @platform ios * @platform ios
*/ */
minimumZoomScale: PropTypes.number, 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). * Called when the momentum scroll starts (scroll which occurs as the ScrollView glides to a stop).
*/ */

Просмотреть файл

@ -8,7 +8,9 @@
package com.facebook.react.views.scroll; package com.facebook.react.views.scroll;
import android.graphics.Color; import android.graphics.Color;
import android.support.v4.view.ViewCompat;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.module.annotations.ReactModule; import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.DisplayMetricsHolder; 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.ReactProp;
import com.facebook.react.uimanager.annotations.ReactPropGroup; import com.facebook.react.uimanager.annotations.ReactPropGroup;
import com.facebook.yoga.YogaConstants; import com.facebook.yoga.YogaConstants;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/** /**
@ -120,6 +123,11 @@ public class ReactHorizontalScrollViewManager
view.setOverScrollMode(ReactScrollViewHelper.parseOverScrollMode(value)); view.setOverScrollMode(ReactScrollViewHelper.parseOverScrollMode(value));
} }
@ReactProp(name = "nestedScrollEnabled")
public void setNestedScrollEnabled(ReactHorizontalScrollView view, boolean value) {
ViewCompat.setNestedScrollingEnabled(view, value);
}
@Override @Override
public void receiveCommand( public void receiveCommand(
ReactHorizontalScrollView scrollView, ReactHorizontalScrollView scrollView,

Просмотреть файл

@ -9,6 +9,8 @@ package com.facebook.react.views.scroll;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.graphics.Color; import android.graphics.Color;
import android.support.v4.view.ViewCompat;
import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.common.MapBuilder; import com.facebook.react.common.MapBuilder;
import com.facebook.react.module.annotations.ReactModule; 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.ReactProp;
import com.facebook.react.uimanager.annotations.ReactPropGroup; import com.facebook.react.uimanager.annotations.ReactPropGroup;
import com.facebook.yoga.YogaConstants; import com.facebook.yoga.YogaConstants;
import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Map;
/** /**
* View manager for {@link ReactScrollView} components. * View manager for {@link ReactScrollView} components.
@ -121,6 +124,11 @@ public class ReactScrollViewManager
view.setOverScrollMode(ReactScrollViewHelper.parseOverScrollMode(value)); view.setOverScrollMode(ReactScrollViewHelper.parseOverScrollMode(value));
} }
@ReactProp(name = "nestedScrollEnabled")
public void setNestedScrollEnabled(ReactScrollView view, boolean value) {
ViewCompat.setNestedScrollingEnabled(view, value);
}
@Override @Override
public @Nullable Map<String, Integer> getCommandsMap() { public @Nullable Map<String, Integer> getCommandsMap() {
return ReactScrollViewCommandHelper.getCommandsMap(); return ReactScrollViewCommandHelper.getCommandsMap();