Browse Source

feat(android props): Add incognito to Android (#524)

José Luis Pereira 5 years ago
parent
commit
25bc5a55c6

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

328
   public void setMessagingEnabled(WebView view, boolean enabled) {
328
   public void setMessagingEnabled(WebView view, boolean enabled) {
329
     ((RNCWebView) view).setMessagingEnabled(enabled);
329
     ((RNCWebView) view).setMessagingEnabled(enabled);
330
   }
330
   }
331
+   
332
+  @ReactProp(name = "incognito")
333
+  public void setIncognito(WebView view, boolean enabled) {
334
+    // Remove all previous cookies
335
+    CookieManager.getInstance().removeAllCookies(null);
336
+
337
+    // Disable caching
338
+    view.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
339
+    view.getSettings().setAppCacheEnabled(!enabled);
340
+    view.clearHistory();
341
+    view.clearCache(enabled);
342
+
343
+    // No form data or autofill enabled
344
+    view.clearFormData();
345
+    view.getSettings().setSavePassword(!enabled);
346
+    view.getSettings().setSaveFormData(!enabled);
347
+  }
331
 
348
 
332
   @ReactProp(name = "source")
349
   @ReactProp(name = "source")
333
   public void setSource(WebView view, @Nullable ReadableMap source) {
350
   public void setSource(WebView view, @Nullable ReadableMap source) {

+ 3
- 3
docs/Reference.md View File

831
 
831
 
832
 Does not store any data within the lifetime of the WebView.
832
 Does not store any data within the lifetime of the WebView.
833
 
833
 
834
-| Type    | Required | Platform      |
835
-| ------- | -------- | ------------- |
836
-| boolean | No       | iOS WKWebView |
834
+| Type    | Required | Platform               |
835
+| ------- | -------- | ---------------------- |
836
+| boolean | No       | Android, iOS WKWebView |
837
 
837
 
838
 ---
838
 ---
839
 
839
 

+ 1
- 1
src/WebViewTypes.ts View File

212
 
212
 
213
 export interface CommonNativeWebViewProps extends ViewProps {
213
 export interface CommonNativeWebViewProps extends ViewProps {
214
   cacheEnabled?: boolean;
214
   cacheEnabled?: boolean;
215
+  incognito?: boolean;
215
   injectedJavaScript?: string;
216
   injectedJavaScript?: string;
216
   mediaPlaybackRequiresUserAction?: boolean;
217
   mediaPlaybackRequiresUserAction?: boolean;
217
   messagingEnabled: boolean;
218
   messagingEnabled: boolean;
258
   decelerationRate?: number;
259
   decelerationRate?: number;
259
   directionalLockEnabled?: boolean;
260
   directionalLockEnabled?: boolean;
260
   hideKeyboardAccessoryView?: boolean;
261
   hideKeyboardAccessoryView?: boolean;
261
-  incognito?: boolean;
262
   pagingEnabled?: boolean;
262
   pagingEnabled?: boolean;
263
   scrollEnabled?: boolean;
263
   scrollEnabled?: boolean;
264
   useSharedProcessPool?: boolean;
264
   useSharedProcessPool?: boolean;