diff --git a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java index e119a98..891c849 100644 --- a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +++ b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java @@ -22,6 +22,7 @@ import android.graphics.Picture; import android.net.Uri; import android.os.Build; import android.text.TextUtils; +import android.view.View; import android.view.ViewGroup.LayoutParams; import android.webkit.ConsoleMessage; import android.webkit.CookieManager; @@ -466,6 +467,24 @@ public class RNCWebViewManager extends SimpleViewManager { view.getSettings().setJavaScriptEnabled(enabled); } + @ReactProp(name = "overScrollMode") + public void setOverScrollMode(WebView view, String overScrollModeString) { + Integer overScrollMode; + switch (overScrollModeString) { + case "never": + overScrollMode = View.OVER_SCROLL_NEVER; + break; + case "content": + overScrollMode = View.OVER_SCROLL_IF_CONTENT_SCROLLS; + break; + case "always": + default: + overScrollMode = View.OVER_SCROLL_ALWAYS; + break; + } + view.setOverScrollMode(overScrollMode); + } + @ReactProp(name = "thirdPartyCookiesEnabled") public void setThirdPartyCookiesEnabled(WebView view, boolean enabled) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { diff --git a/docs/Reference.md b/docs/Reference.md index fe4f55c..a3587b4 100644 --- a/docs/Reference.md +++ b/docs/Reference.md @@ -34,6 +34,7 @@ This document lays out the current public properties and methods for the React N - [`userAgent`](Reference.md#useragent) - [`allowsInlineMediaPlayback`](Reference.md#allowsinlinemediaplayback) - [`bounces`](Reference.md#bounces) +- [`overScrollMode`](Reference.md#overscrollmode) - [`contentInset`](Reference.md#contentinset) - [`dataDetectorTypes`](Reference.md#datadetectortypes) - [`scrollEnabled`](Reference.md#scrollenabled) @@ -371,6 +372,22 @@ Boolean value that determines whether the web view bounces when it reaches the e --- +### `overScrollMode` + +Specifies the over scroll mode. + +Possible values for `overScrollMode` are: + +- `always` (default) - Always allow a user to over-scroll this view, provided it is a view that can scroll. +- `content` - Allow a user to over-scroll this view only if the content is large enough to meaningfully scroll, provided it is a view that can scroll. +- `never` - Never allow a user to over-scroll this view. + +| Type | Required | Platform | +| ------ | -------- | -------- | +| string | No | Android | + +--- + ### `contentInset` The amount by which the web view content is inset from the edges of the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}. diff --git a/js/WebView.android.js b/js/WebView.android.js index f0693d1..1dc7743 100644 --- a/js/WebView.android.js +++ b/js/WebView.android.js @@ -62,6 +62,7 @@ type State = {| */ class WebView extends React.Component { static defaultProps = { + overScrollMode: 'always', javaScriptEnabled: true, thirdPartyCookiesEnabled: true, scalesPageToFit: true, @@ -145,6 +146,7 @@ class WebView extends React.Component { domStorageEnabled={this.props.domStorageEnabled} messagingEnabled={typeof this.props.onMessage === 'function'} onMessage={this.onMessage} + overScrollMode={this.props.overScrollMode} contentInset={this.props.contentInset} automaticallyAdjustContentInsets={ this.props.automaticallyAdjustContentInsets diff --git a/js/WebViewTypes.js b/js/WebViewTypes.js index 958b575..0929baf 100644 --- a/js/WebViewTypes.js +++ b/js/WebViewTypes.js @@ -75,6 +75,8 @@ export type DataDetectorTypes = | 'none' | 'all'; +export type OverScrollModeType = 'always' | 'content' | 'never'; + export type WebViewSourceUri = $ReadOnly<{| /** * The URI to load in the `WebView`. Can be a local or remote file. @@ -223,6 +225,18 @@ export type AndroidWebViewProps = $ReadOnly<{| onNavigationStateChange?: (event: WebViewNavigation) => mixed, onContentSizeChange?: (event: WebViewEvent) => mixed, + /** + * https://developer.android.com/reference/android/view/View#OVER_SCROLL_NEVER + * Sets the overScrollMode. Possible values are: + * + * - `'always'` (default) + * - `'content'` + * - `'never'` + * + * @platform android + */ + overScrollMode?: ?OverScrollModeType, + /** * Sets whether Geolocation is enabled. The default is false. * @platform android