diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 1c7b704c8..afc4306d2 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -349,6 +349,24 @@ const ScrollView = React.createClass({ * @platform android */ scrollPerfTag: PropTypes.string, + + /** + * Used to override default value of overScroll mode. + * + * Possible values: + * + * - `'auto'` - Default value, allow a user to over-scroll + * this view only if the content is large enough to meaningfully scroll. + * - `'always'` - Always allow a user to over-scroll this view. + * - `'never'` - Never allow a user to over-scroll this view. + * + * @platform android + */ + overScrollMode: PropTypes.oneOf([ + 'auto', + 'always', + 'never', + ]), }, mixins: [ScrollResponder.Mixin], 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 769a90738..2b0fe746e 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 @@ -12,6 +12,7 @@ package com.facebook.react.views.scroll; import javax.annotation.Nullable; import android.graphics.Color; +import android.view.View; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.module.annotations.ReactModule; @@ -98,6 +99,14 @@ public class ReactHorizontalScrollViewManager view.setPagingEnabled(pagingEnabled); } + /** + * Controls overScroll behaviour + */ + @ReactProp(name = "overScrollMode") + public void setOverScrollMode(ReactHorizontalScrollView view, String value) { + view.setOverScrollMode(ReactScrollViewHelper.parseOverScrollMode(value)); + } + @Override public void receiveCommand( ReactHorizontalScrollView scrollView, diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java index 966c50bb3..567cf9bb9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java @@ -12,6 +12,7 @@ package com.facebook.react.views.scroll; import android.view.View; import android.view.ViewGroup; +import com.facebook.react.bridge.JSApplicationIllegalArgumentException; import com.facebook.react.bridge.ReactContext; import com.facebook.react.uimanager.UIManagerModule; @@ -21,6 +22,9 @@ import com.facebook.react.uimanager.UIManagerModule; public class ReactScrollViewHelper { public static final long MOMENTUM_DELAY = 20; + public static final String OVER_SCROLL_ALWAYS = "always"; + public static final String AUTO = "auto"; + public static final String OVER_SCROLL_NEVER = "never"; /** * Shared by {@link ReactScrollView} and {@link ReactHorizontalScrollView}. @@ -64,4 +68,16 @@ public class ReactScrollViewHelper { scrollView.getWidth(), scrollView.getHeight())); } + + public static int parseOverScrollMode(String jsOverScrollMode) { + if (jsOverScrollMode == null || jsOverScrollMode.equals(AUTO)) { + return View.OVER_SCROLL_IF_CONTENT_SCROLLS; + } else if (jsOverScrollMode.equals(OVER_SCROLL_ALWAYS)) { + return View.OVER_SCROLL_ALWAYS; + } else if (jsOverScrollMode.equals(OVER_SCROLL_NEVER)) { + return View.OVER_SCROLL_NEVER; + } else { + throw new JSApplicationIllegalArgumentException("wrong overScrollMode: " + jsOverScrollMode); + } + } } 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 76cc41ac9..c70f8cebc 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 @@ -14,6 +14,7 @@ import javax.annotation.Nullable; import java.util.Map; import android.graphics.Color; +import android.view.View; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.common.MapBuilder; @@ -107,6 +108,14 @@ public class ReactScrollViewManager view.setEndFillColor(color); } + /** + * Controls overScroll behaviour + */ + @ReactProp(name = "overScrollMode") + public void setOverScrollMode(ReactScrollView view, String value) { + view.setOverScrollMode(ReactScrollViewHelper.parseOverScrollMode(value)); + } + @Override public @Nullable Map getCommandsMap() { return ReactScrollViewCommandHelper.getCommandsMap();