Kaynağa Gözat

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

Bae Hyeonseung 5 yıl önce
ebeveyn
işleme
7f35344632

+ 12
- 0
docs/Reference.md Dosyayı Görüntüle

@@ -44,6 +44,7 @@ This document lays out the current public properties and methods for the React N
44 44
 - [`url`](Reference.md#url)
45 45
 - [`html`](Reference.md#html)
46 46
 - [`hideKeyboardAccessoryView`](Reference.md#hidekeyboardaccessoryview)
47
+- [`allowsBackForwardNavigationGestures`](Reference.md#allowsbackforwardnavigationgestures)
47 48
 
48 49
 ## Methods Index
49 50
 
@@ -494,6 +495,17 @@ If true, this will hide the keyboard accessory view (< > and Done) when using th
494 495
 | ------- | -------- | -------- |
495 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 509
 ## Methods
498 510
 
499 511
 ### `extraNativeComponentConfig()`

+ 1
- 0
ios/RNCWKWebView.h Dosyayı Görüntüle

@@ -36,6 +36,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
36 36
 @property (nonatomic, assign) UIEdgeInsets contentInset;
37 37
 @property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
38 38
 @property (nonatomic, assign) BOOL hideKeyboardAccessoryView;
39
+@property (nonatomic, assign) BOOL allowsBackForwardNavigationGestures;
39 40
 
40 41
 - (void)postMessage:(NSString *)message;
41 42
 - (void)injectJavaScript:(NSString *)script;

+ 1
- 0
ios/RNCWKWebView.m Dosyayı Görüntüle

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

+ 1
- 0
ios/RNCWKWebViewManager.m Dosyayı Görüntüle

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

+ 9
- 0
js/WebView.ios.js Dosyayı Görüntüle

@@ -151,6 +151,14 @@ class WebView extends React.Component<WebViewSharedProps, State> {
151 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 164
   render() {
@@ -262,6 +270,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
262 270
           this.props.automaticallyAdjustContentInsets
263 271
         }
264 272
         hideKeyboardAccessoryView={this.props.hideKeyboardAccessoryView}
273
+        allowsBackForwardNavigationGestures={this.props.allowsBackForwardNavigationGestures}
265 274
         onLoadingStart={this._onLoadingStart}
266 275
         onLoadingFinish={this._onLoadingFinish}
267 276
         onLoadingError={this._onLoadingError}

+ 5
- 0
js/WebViewTypes.js Dosyayı Görüntüle

@@ -224,6 +224,11 @@ export type IOSWebViewProps = $ReadOnly<{|
224 224
    * backward compatible.
225 225
    */
226 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 234
 export type AndroidWebViewProps = $ReadOnly<{|