Browse Source

feat(WKWebview): [iOS] Add 'allowsBackForwardNavigationGestures' property (#97)

Bae Hyeonseung 6 years ago
parent
commit
7f35344632
6 changed files with 29 additions and 0 deletions
  1. 12
    0
      docs/Reference.md
  2. 1
    0
      ios/RNCWKWebView.h
  3. 1
    0
      ios/RNCWKWebView.m
  4. 1
    0
      ios/RNCWKWebViewManager.m
  5. 9
    0
      js/WebView.ios.js
  6. 5
    0
      js/WebViewTypes.js

+ 12
- 0
docs/Reference.md View File

44
 - [`url`](Reference.md#url)
44
 - [`url`](Reference.md#url)
45
 - [`html`](Reference.md#html)
45
 - [`html`](Reference.md#html)
46
 - [`hideKeyboardAccessoryView`](Reference.md#hidekeyboardaccessoryview)
46
 - [`hideKeyboardAccessoryView`](Reference.md#hidekeyboardaccessoryview)
47
+- [`allowsBackForwardNavigationGestures`](Reference.md#allowsbackforwardnavigationgestures)
47
 
48
 
48
 ## Methods Index
49
 ## Methods Index
49
 
50
 
494
 | ------- | -------- | -------- |
495
 | ------- | -------- | -------- |
495
 | boolean | No       | iOS      |
496
 | boolean | No       | iOS      |
496
 
497
 
498
+---
499
+
500
+### `allowsBackForwardNavigationGestures`
501
+
502
+If true, this will be able horizontal swipe gestures when using the WKWebView. The default value is `false`.
503
+
504
+| Type    | Required | Platform |
505
+| ------- | -------- | -------- |
506
+| boolean | No       | iOS      |
507
+
508
+
497
 ## Methods
509
 ## Methods
498
 
510
 
499
 ### `extraNativeComponentConfig()`
511
 ### `extraNativeComponentConfig()`

+ 1
- 0
ios/RNCWKWebView.h View File

36
 @property (nonatomic, assign) UIEdgeInsets contentInset;
36
 @property (nonatomic, assign) UIEdgeInsets contentInset;
37
 @property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
37
 @property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
38
 @property (nonatomic, assign) BOOL hideKeyboardAccessoryView;
38
 @property (nonatomic, assign) BOOL hideKeyboardAccessoryView;
39
+@property (nonatomic, assign) BOOL allowsBackForwardNavigationGestures;
39
 
40
 
40
 - (void)postMessage:(NSString *)message;
41
 - (void)postMessage:(NSString *)message;
41
 - (void)injectJavaScript:(NSString *)script;
42
 - (void)injectJavaScript:(NSString *)script;

+ 1
- 0
ios/RNCWKWebView.m View File

102
     _webView.scrollView.scrollEnabled = _scrollEnabled;
102
     _webView.scrollView.scrollEnabled = _scrollEnabled;
103
     _webView.scrollView.bounces = _bounces;
103
     _webView.scrollView.bounces = _bounces;
104
     [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
104
     [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
105
+    _webView.allowsBackForwardNavigationGestures = _allowsBackForwardNavigationGestures;
105
 
106
 
106
 #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
107
 #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
107
     if ([_webView.scrollView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
108
     if ([_webView.scrollView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {

+ 1
- 0
ios/RNCWKWebViewManager.m View File

44
 RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
44
 RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
45
 RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL)
45
 RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL)
46
 RCT_EXPORT_VIEW_PROPERTY(hideKeyboardAccessoryView, BOOL)
46
 RCT_EXPORT_VIEW_PROPERTY(hideKeyboardAccessoryView, BOOL)
47
+RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL)
47
 
48
 
48
 /**
49
 /**
49
  * Expose methods to enable messaging the webview.
50
  * Expose methods to enable messaging the webview.

+ 9
- 0
js/WebView.ios.js View File

151
         'The scalesPageToFit property is not supported when useWebKit = true',
151
         'The scalesPageToFit property is not supported when useWebKit = true',
152
       );
152
       );
153
     }
153
     }
154
+    if (
155
+      !this.props.useWebKit &&
156
+      this.props.allowsBackForwardNavigationGestures
157
+    ) {
158
+      console.warn(
159
+        'The allowsBackForwardNavigationGestures property is not supported when useWebKit = false',
160
+      );
161
+    }
154
   }
162
   }
155
 
163
 
156
   render() {
164
   render() {
262
           this.props.automaticallyAdjustContentInsets
270
           this.props.automaticallyAdjustContentInsets
263
         }
271
         }
264
         hideKeyboardAccessoryView={this.props.hideKeyboardAccessoryView}
272
         hideKeyboardAccessoryView={this.props.hideKeyboardAccessoryView}
273
+        allowsBackForwardNavigationGestures={this.props.allowsBackForwardNavigationGestures}
265
         onLoadingStart={this._onLoadingStart}
274
         onLoadingStart={this._onLoadingStart}
266
         onLoadingFinish={this._onLoadingFinish}
275
         onLoadingFinish={this._onLoadingFinish}
267
         onLoadingError={this._onLoadingError}
276
         onLoadingError={this._onLoadingError}

+ 5
- 0
js/WebViewTypes.js View File

224
    * backward compatible.
224
    * backward compatible.
225
    */
225
    */
226
   hideKeyboardAccessoryView?: ?boolean,
226
   hideKeyboardAccessoryView?: ?boolean,
227
+  /**
228
+   * A Boolean value indicating whether horizontal swipe gestures will trigger
229
+   * back-forward list navigations.
230
+   */
231
+  allowsBackForwardNavigationGestures?: ?boolean,
227
 |}>;
232
 |}>;
228
 
233
 
229
 export type AndroidWebViewProps = $ReadOnly<{|
234
 export type AndroidWebViewProps = $ReadOnly<{|