Browse Source

feat(WKWebview): Add incognito prop to iOS WKWebview

Allows the webview to be opened with an ephemeral data storage.
José Luis Pereira 5 years ago
parent
commit
62f871c186
6 changed files with 32 additions and 0 deletions
  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 View File

44
 - [`html`](Reference.md#html)
44
 - [`html`](Reference.md#html)
45
 - [`hideKeyboardAccessoryView`](Reference.md#hidekeyboardaccessoryview)
45
 - [`hideKeyboardAccessoryView`](Reference.md#hidekeyboardaccessoryview)
46
 - [`allowsBackForwardNavigationGestures`](Reference.md#allowsbackforwardnavigationgestures)
46
 - [`allowsBackForwardNavigationGestures`](Reference.md#allowsbackforwardnavigationgestures)
47
+- [`incognito`](Reference.md#incognito)
47
 - [`allowFileAccess`](Reference.md#allowFileAccess)
48
 - [`allowFileAccess`](Reference.md#allowFileAccess)
48
 - [`saveFormDataDisabled`](Reference.md#saveFormDataDisabled)
49
 - [`saveFormDataDisabled`](Reference.md#saveFormDataDisabled)
49
 - [`pagingEnabled`](Reference.md#pagingEnabled)
50
 - [`pagingEnabled`](Reference.md#pagingEnabled)
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
 ### `allowFileAccess`
525
 ### `allowFileAccess`
515
 
526
 
516
 If true, this will allow access to the file system via `file://` URI's. The default value is `false`.
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 View File

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

+ 3
- 0
ios/RNCWKWebView.m View File

81
     };
81
     };
82
 
82
 
83
     WKWebViewConfiguration *wkWebViewConfig = [WKWebViewConfiguration new];
83
     WKWebViewConfiguration *wkWebViewConfig = [WKWebViewConfiguration new];
84
+    if (_incognito) {
85
+      wkWebViewConfig.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
86
+    }
84
     if(self.useSharedProcessPool) {
87
     if(self.useSharedProcessPool) {
85
         wkWebViewConfig.processPool = [[RNCWKProcessPoolManager sharedManager] sharedProcessPool];
88
         wkWebViewConfig.processPool = [[RNCWKProcessPoolManager sharedManager] sharedProcessPool];
86
     }
89
     }

+ 1
- 0
ios/RNCWKWebViewManager.m View File

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
 RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL)
48
+RCT_EXPORT_VIEW_PROPERTY(incognito, BOOL)
48
 RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL)
49
 RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL)
49
 RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString)
50
 RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString)
50
 RCT_EXPORT_VIEW_PROPERTY(allowsLinkPreview, BOOL)
51
 RCT_EXPORT_VIEW_PROPERTY(allowsLinkPreview, BOOL)

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

168
         'The allowsBackForwardNavigationGestures property is not supported when useWebKit = false',
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
   render() {
182
   render() {
252
         }
261
         }
253
         hideKeyboardAccessoryView={this.props.hideKeyboardAccessoryView}
262
         hideKeyboardAccessoryView={this.props.hideKeyboardAccessoryView}
254
         allowsBackForwardNavigationGestures={this.props.allowsBackForwardNavigationGestures}
263
         allowsBackForwardNavigationGestures={this.props.allowsBackForwardNavigationGestures}
264
+        incognito={this.props.incognito}
255
         userAgent={this.props.userAgent}
265
         userAgent={this.props.userAgent}
256
         onLoadingStart={this._onLoadingStart}
266
         onLoadingStart={this._onLoadingStart}
257
         onLoadingFinish={this._onLoadingFinish}
267
         onLoadingFinish={this._onLoadingFinish}
443
     }
453
     }
444
 
454
 
445
     this._showRedboxOnPropChanges(prevProps, 'allowsInlineMediaPlayback');
455
     this._showRedboxOnPropChanges(prevProps, 'allowsInlineMediaPlayback');
456
+    this._showRedboxOnPropChanges(prevProps, 'incognito');
446
     this._showRedboxOnPropChanges(prevProps, 'mediaPlaybackRequiresUserAction');
457
     this._showRedboxOnPropChanges(prevProps, 'mediaPlaybackRequiresUserAction');
447
     this._showRedboxOnPropChanges(prevProps, 'dataDetectorTypes');
458
     this._showRedboxOnPropChanges(prevProps, 'dataDetectorTypes');
448
 
459
 

+ 5
- 0
js/WebViewTypes.js View File

365
    */
365
    */
366
   source?: ?WebViewSource,
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
    * Function that returns a view to show if there's an error.
374
    * Function that returns a view to show if there's an error.
370
    */
375
    */