Browse Source

[android] finalise `enableCache` android support, uses `setAppCachePath` & `setAppCacheEnabled`

Salakar 6 years ago
parent
commit
6d70deaff8

+ 11
- 1
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java View File

1
 package com.reactnativecommunity.webview;
1
 package com.reactnativecommunity.webview;
2
 
2
 
3
+import android.annotation.SuppressLint;
3
 import android.annotation.TargetApi;
4
 import android.annotation.TargetApi;
4
 import android.content.Context;
5
 import android.content.Context;
6
+
5
 import com.facebook.react.uimanager.UIManagerModule;
7
 import com.facebook.react.uimanager.UIManagerModule;
8
+
6
 import java.util.LinkedList;
9
 import java.util.LinkedList;
7
 import java.util.List;
10
 import java.util.List;
8
 import java.util.regex.Pattern;
11
 import java.util.regex.Pattern;
303
       return new RNCWebViewBridge(webView);
306
       return new RNCWebViewBridge(webView);
304
     }
307
     }
305
 
308
 
309
+    @SuppressLint("AddJavascriptInterface")
306
     public void setMessagingEnabled(boolean enabled) {
310
     public void setMessagingEnabled(boolean enabled) {
307
       if (messagingEnabled == enabled) {
311
       if (messagingEnabled == enabled) {
308
         return;
312
         return;
484
   @ReactProp(name = "enableCache")
488
   @ReactProp(name = "enableCache")
485
   public void setCacheEnabled(WebView view, boolean enabled) {
489
   public void setCacheEnabled(WebView view, boolean enabled) {
486
     if (enabled) {
490
     if (enabled) {
487
-      view.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
491
+      Context ctx = view.getContext();
492
+      if (ctx != null) {
493
+        view.getSettings().setAppCachePath(ctx.getCacheDir().getAbsolutePath());
494
+        view.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
495
+        view.getSettings().setAppCacheEnabled(true);
496
+      }
488
     } else {
497
     } else {
489
       view.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
498
       view.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
499
+      view.getSettings().setAppCacheEnabled(false);
490
     }
500
     }
491
   }
501
   }
492
 
502