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 https://github.com/facebook/react-native/pull/10905

Differential Revision: D4500957

Pulled By: mkonicek

fbshipit-source-id: 873eba38183defba133c228e0c1038efa83297d3
This commit is contained in:
Adam Comella 2017-02-02 04:13:20 -08:00 committed by Facebook Github Bot
parent a45246e354
commit 12c4868628
4 changed files with 52 additions and 0 deletions

View File

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

View File

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

View File

@ -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);
}
}
}

View File

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