Sfoglia il codice sorgente

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

Thibault Malbranche 6 anni fa
parent
commit
2c0059ff61
No account linked to committer's email address

+ 19
- 0
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java Vedi File

@@ -22,6 +22,7 @@ import android.graphics.Picture;
22 22
 import android.net.Uri;
23 23
 import android.os.Build;
24 24
 import android.text.TextUtils;
25
+import android.view.View;
25 26
 import android.view.ViewGroup.LayoutParams;
26 27
 import android.webkit.ConsoleMessage;
27 28
 import android.webkit.CookieManager;
@@ -466,6 +467,24 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
466 467
     view.getSettings().setJavaScriptEnabled(enabled);
467 468
   }
468 469
 
470
+  @ReactProp(name = "overScrollMode")
471
+  public void setOverScrollMode(WebView view, String overScrollModeString) {
472
+    Integer overScrollMode;
473
+    switch (overScrollModeString) {
474
+      case "never":
475
+        overScrollMode = View.OVER_SCROLL_NEVER;
476
+        break;
477
+      case "content":
478
+        overScrollMode = View.OVER_SCROLL_IF_CONTENT_SCROLLS;
479
+        break;
480
+      case "always":
481
+      default:
482
+        overScrollMode = View.OVER_SCROLL_ALWAYS;
483
+        break;
484
+    }
485
+    view.setOverScrollMode(overScrollMode);
486
+  }
487
+
469 488
   @ReactProp(name = "thirdPartyCookiesEnabled")
470 489
   public void setThirdPartyCookiesEnabled(WebView view, boolean enabled) {
471 490
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

+ 17
- 0
docs/Reference.md Vedi File

@@ -34,6 +34,7 @@ This document lays out the current public properties and methods for the React N
34 34
 - [`userAgent`](Reference.md#useragent)
35 35
 - [`allowsInlineMediaPlayback`](Reference.md#allowsinlinemediaplayback)
36 36
 - [`bounces`](Reference.md#bounces)
37
+- [`overScrollMode`](Reference.md#overscrollmode)
37 38
 - [`contentInset`](Reference.md#contentinset)
38 39
 - [`dataDetectorTypes`](Reference.md#datadetectortypes)
39 40
 - [`scrollEnabled`](Reference.md#scrollenabled)
@@ -371,6 +372,22 @@ Boolean value that determines whether the web view bounces when it reaches the e
371 372
 
372 373
 ---
373 374
 
375
+### `overScrollMode`
376
+
377
+Specifies the over scroll mode.
378
+
379
+Possible values for `overScrollMode` are:
380
+
381
+- `always` (default) - Always allow a user to over-scroll this view, provided it is a view that can scroll.
382
+- `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.
383
+- `never` - Never allow a user to over-scroll this view.
384
+
385
+| Type   | Required | Platform |
386
+| ------ | -------- | -------- |
387
+| string | No       | Android  |
388
+
389
+---
390
+
374 391
 ### `contentInset`
375 392
 
376 393
 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}.

+ 2
- 0
js/WebView.android.js Vedi File

@@ -62,6 +62,7 @@ type State = {|
62 62
  */
63 63
 class WebView extends React.Component<WebViewSharedProps, State> {
64 64
   static defaultProps = {
65
+    overScrollMode: 'always',
65 66
     javaScriptEnabled: true,
66 67
     thirdPartyCookiesEnabled: true,
67 68
     scalesPageToFit: true,
@@ -145,6 +146,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
145 146
         domStorageEnabled={this.props.domStorageEnabled}
146 147
         messagingEnabled={typeof this.props.onMessage === 'function'}
147 148
         onMessage={this.onMessage}
149
+        overScrollMode={this.props.overScrollMode}
148 150
         contentInset={this.props.contentInset}
149 151
         automaticallyAdjustContentInsets={
150 152
           this.props.automaticallyAdjustContentInsets

+ 14
- 0
js/WebViewTypes.js Vedi File

@@ -75,6 +75,8 @@ export type DataDetectorTypes =
75 75
   | 'none'
76 76
   | 'all';
77 77
 
78
+export type OverScrollModeType = 'always' | 'content' | 'never';
79
+
78 80
 export type WebViewSourceUri = $ReadOnly<{|
79 81
   /**
80 82
    * The URI to load in the `WebView`. Can be a local or remote file.
@@ -223,6 +225,18 @@ export type AndroidWebViewProps = $ReadOnly<{|
223 225
   onNavigationStateChange?: (event: WebViewNavigation) => mixed,
224 226
   onContentSizeChange?: (event: WebViewEvent) => mixed,
225 227
 
228
+  /**
229
+   * https://developer.android.com/reference/android/view/View#OVER_SCROLL_NEVER
230
+   * Sets the overScrollMode. Possible values are:
231
+   *
232
+   * - `'always'` (default)
233
+   * - `'content'`
234
+   * - `'never'`
235
+   *
236
+   * @platform android
237
+   */
238
+  overScrollMode?: ?OverScrollModeType,
239
+
226 240
   /**
227 241
    * Sets whether Geolocation is enabled. The default is false.
228 242
    * @platform android