Permalink
Browse files

Android: Add overScrollMode prop to ScrollView

Summary:
This prop exposes the functionality provided by Android ScrollView's setOverScrollMode method.

One interesting thing to note is that, if you were to read the Android docs, you would think that the value "always" is the default over scroll mode. However, the docs are incorrect and "always-if-content-scrolls" is actually the default value (http://stackoverflow.com/a/27116306).

**Test plan (required)**

Verified this change in a test app. Also, our team uses this change in our app.

Adam Comella
Microsoft Corp.
Closes #10905

Differential Revision: D4500957

Pulled By: mkonicek

fbshipit-source-id: 873eba38183defba133c228e0c1038efa83297d3
  • Loading branch information...
rigdern authored and facebook-github-bot committed Feb 2, 2017
1 parent a45246e commit 12c486862896ca2391577410656dfc4580361fef
@@ -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],
@@ -12,6 +12,7 @@
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 void setPagingEnabled(ReactHorizontalScrollView view, boolean pagingEnabl
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,
@@ -12,6 +12,7 @@
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 @@
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 @@ private static void emitScrollEvent(ViewGroup scrollView, ScrollEventType scroll
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);
}
}
}
@@ -14,6 +14,7 @@
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 void setBottomFillColor(ReactScrollView view, int color) {
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<String, Integer> getCommandsMap() {
return ReactScrollViewCommandHelper.getCommandsMap();

0 comments on commit 12c4868

Please sign in to comment.