Browse Source

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

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

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

22
 import android.net.Uri;
22
 import android.net.Uri;
23
 import android.os.Build;
23
 import android.os.Build;
24
 import android.text.TextUtils;
24
 import android.text.TextUtils;
25
+import android.view.View;
25
 import android.view.ViewGroup.LayoutParams;
26
 import android.view.ViewGroup.LayoutParams;
26
 import android.webkit.ConsoleMessage;
27
 import android.webkit.ConsoleMessage;
27
 import android.webkit.CookieManager;
28
 import android.webkit.CookieManager;
466
     view.getSettings().setJavaScriptEnabled(enabled);
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
   @ReactProp(name = "thirdPartyCookiesEnabled")
488
   @ReactProp(name = "thirdPartyCookiesEnabled")
470
   public void setThirdPartyCookiesEnabled(WebView view, boolean enabled) {
489
   public void setThirdPartyCookiesEnabled(WebView view, boolean enabled) {
471
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
490
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

+ 17
- 0
docs/Reference.md View File

34
 - [`userAgent`](Reference.md#useragent)
34
 - [`userAgent`](Reference.md#useragent)
35
 - [`allowsInlineMediaPlayback`](Reference.md#allowsinlinemediaplayback)
35
 - [`allowsInlineMediaPlayback`](Reference.md#allowsinlinemediaplayback)
36
 - [`bounces`](Reference.md#bounces)
36
 - [`bounces`](Reference.md#bounces)
37
+- [`overScrollMode`](Reference.md#overscrollmode)
37
 - [`contentInset`](Reference.md#contentinset)
38
 - [`contentInset`](Reference.md#contentinset)
38
 - [`dataDetectorTypes`](Reference.md#datadetectortypes)
39
 - [`dataDetectorTypes`](Reference.md#datadetectortypes)
39
 - [`scrollEnabled`](Reference.md#scrollenabled)
40
 - [`scrollEnabled`](Reference.md#scrollenabled)
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
 ### `contentInset`
391
 ### `contentInset`
375
 
392
 
376
 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}.
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 View File

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

+ 14
- 0
js/WebViewTypes.js View File

75
   | 'none'
75
   | 'none'
76
   | 'all';
76
   | 'all';
77
 
77
 
78
+export type OverScrollModeType = 'always' | 'content' | 'never';
79
+
78
 export type WebViewSourceUri = $ReadOnly<{|
80
 export type WebViewSourceUri = $ReadOnly<{|
79
   /**
81
   /**
80
    * The URI to load in the `WebView`. Can be a local or remote file.
82
    * The URI to load in the `WebView`. Can be a local or remote file.
223
   onNavigationStateChange?: (event: WebViewNavigation) => mixed,
225
   onNavigationStateChange?: (event: WebViewNavigation) => mixed,
224
   onContentSizeChange?: (event: WebViewEvent) => mixed,
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
    * Sets whether Geolocation is enabled. The default is false.
241
    * Sets whether Geolocation is enabled. The default is false.
228
    * @platform android
242
    * @platform android