feat(New Webview Prop): Added Android overscroll property (#54)

This commit is contained in:
Thibault Malbranche 2018-10-17 16:48:19 +02:00 committed by GitHub
parent cd00bdc96b
commit 2c0059ff61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 0 deletions

View File

@ -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<WebView> {
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) {

View File

@ -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}.

View File

@ -62,6 +62,7 @@ type State = {|
*/
class WebView extends React.Component<WebViewSharedProps, State> {
static defaultProps = {
overScrollMode: 'always',
javaScriptEnabled: true,
thirdPartyCookiesEnabled: true,
scalesPageToFit: true,
@ -145,6 +146,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
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

View File

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