Просмотр исходного кода

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

José Luis Pereira 5 лет назад
Родитель
Сommit
25bc5a55c6

+ 17
- 0
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java Просмотреть файл

@@ -328,6 +328,23 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
328 328
   public void setMessagingEnabled(WebView view, boolean enabled) {
329 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 349
   @ReactProp(name = "source")
333 350
   public void setSource(WebView view, @Nullable ReadableMap source) {

+ 3
- 3
docs/Reference.md Просмотреть файл

@@ -831,9 +831,9 @@ If true, this will be able horizontal swipe gestures when using the WKWebView. T
831 831
 
832 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 Просмотреть файл

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