Explorar el Código

feat(WKWebview): Add incognito prop to iOS WKWebview

Allows the webview to be opened with an ephemeral data storage.
José Luis Pereira hace 5 años
padre
commit
62f871c186
Se han modificado 6 ficheros con 32 adiciones y 0 borrados
  1. 11
    0
      docs/Reference.md
  2. 1
    0
      ios/RNCWKWebView.h
  3. 3
    0
      ios/RNCWKWebView.m
  4. 1
    0
      ios/RNCWKWebViewManager.m
  5. 11
    0
      js/WebView.ios.js
  6. 5
    0
      js/WebViewTypes.js

+ 11
- 0
docs/Reference.md Ver fichero

@@ -44,6 +44,7 @@ This document lays out the current public properties and methods for the React N
44 44
 - [`html`](Reference.md#html)
45 45
 - [`hideKeyboardAccessoryView`](Reference.md#hidekeyboardaccessoryview)
46 46
 - [`allowsBackForwardNavigationGestures`](Reference.md#allowsbackforwardnavigationgestures)
47
+- [`incognito`](Reference.md#incognito)
47 48
 - [`allowFileAccess`](Reference.md#allowFileAccess)
48 49
 - [`saveFormDataDisabled`](Reference.md#saveFormDataDisabled)
49 50
 - [`pagingEnabled`](Reference.md#pagingEnabled)
@@ -511,6 +512,16 @@ If true, this will be able horizontal swipe gestures when using the WKWebView. T
511 512
 
512 513
 ---
513 514
 
515
+### `incognito`
516
+
517
+Does not store any data within the lifetime of the WebView.
518
+
519
+| Type    | Required | Platform      |
520
+| ------- | -------- | ------------- |
521
+| boolean | No       | iOS WKWebView |
522
+
523
+---
524
+
514 525
 ### `allowFileAccess`
515 526
 
516 527
 If true, this will allow access to the file system via `file://` URI's. The default value is `false`.

+ 1
- 0
ios/RNCWKWebView.h Ver fichero

@@ -38,6 +38,7 @@
38 38
 @property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
39 39
 @property (nonatomic, assign) BOOL hideKeyboardAccessoryView;
40 40
 @property (nonatomic, assign) BOOL allowsBackForwardNavigationGestures;
41
+@property (nonatomic, assign) BOOL incognito;
41 42
 @property (nonatomic, assign) BOOL useSharedProcessPool;
42 43
 @property (nonatomic, copy) NSString *userAgent;
43 44
 @property (nonatomic, assign) BOOL allowsLinkPreview;

+ 3
- 0
ios/RNCWKWebView.m Ver fichero

@@ -81,6 +81,9 @@ static NSString *const MessageHanderName = @"ReactNative";
81 81
     };
82 82
 
83 83
     WKWebViewConfiguration *wkWebViewConfig = [WKWebViewConfiguration new];
84
+    if (_incognito) {
85
+      wkWebViewConfig.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
86
+    }
84 87
     if(self.useSharedProcessPool) {
85 88
         wkWebViewConfig.processPool = [[RNCWKProcessPoolManager sharedManager] sharedProcessPool];
86 89
     }

+ 1
- 0
ios/RNCWKWebViewManager.m Ver fichero

@@ -45,6 +45,7 @@ RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
45 45
 RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL)
46 46
 RCT_EXPORT_VIEW_PROPERTY(hideKeyboardAccessoryView, BOOL)
47 47
 RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL)
48
+RCT_EXPORT_VIEW_PROPERTY(incognito, BOOL)
48 49
 RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL)
49 50
 RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString)
50 51
 RCT_EXPORT_VIEW_PROPERTY(allowsLinkPreview, BOOL)

+ 11
- 0
js/WebView.ios.js Ver fichero

@@ -168,6 +168,15 @@ class WebView extends React.Component<WebViewSharedProps, State> {
168 168
         'The allowsBackForwardNavigationGestures property is not supported when useWebKit = false',
169 169
       );
170 170
     }
171
+
172
+    if (
173
+      !this.props.useWebKit &&
174
+      this.props.incognito
175
+    ) {
176
+      console.warn(
177
+        'The incognito property is not supported when useWebKit = false',
178
+      );
179
+    }
171 180
   }
172 181
 
173 182
   render() {
@@ -252,6 +261,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
252 261
         }
253 262
         hideKeyboardAccessoryView={this.props.hideKeyboardAccessoryView}
254 263
         allowsBackForwardNavigationGestures={this.props.allowsBackForwardNavigationGestures}
264
+        incognito={this.props.incognito}
255 265
         userAgent={this.props.userAgent}
256 266
         onLoadingStart={this._onLoadingStart}
257 267
         onLoadingFinish={this._onLoadingFinish}
@@ -443,6 +453,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
443 453
     }
444 454
 
445 455
     this._showRedboxOnPropChanges(prevProps, 'allowsInlineMediaPlayback');
456
+    this._showRedboxOnPropChanges(prevProps, 'incognito');
446 457
     this._showRedboxOnPropChanges(prevProps, 'mediaPlaybackRequiresUserAction');
447 458
     this._showRedboxOnPropChanges(prevProps, 'dataDetectorTypes');
448 459
 

+ 5
- 0
js/WebViewTypes.js Ver fichero

@@ -365,6 +365,11 @@ export type WebViewSharedProps = $ReadOnly<{|
365 365
    */
366 366
   source?: ?WebViewSource,
367 367
 
368
+  /**
369
+   * Does not store any data within the lifetime of the WebView.
370
+   */
371
+  incognito?: ?boolean,
372
+
368 373
   /**
369 374
    * Function that returns a view to show if there's an error.
370 375
    */