mirror of
https://github.com/status-im/react-native-webview.git
synced 2026-08-31 11:41:08 +00:00
feat(iOS/Android): Add cacheEnabled prop (#152)
Added a new cacheEnabled prop to toggle Android & iOS webview caching behavior. BREAKING CHANGE: This change makes caching enabled by default when previously there was no caching behavior which may cause unexpected behaviour changes in your existing implementations.
This commit is contained in:
committed by
Thibault Malbranche
parent
de4130c7d8
commit
83ce79ff89
@@ -1,8 +1,10 @@
|
||||
package com.reactnativecommunity.webview;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.Context;
|
||||
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
@@ -303,6 +305,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
return new RNCWebViewBridge(webView);
|
||||
}
|
||||
|
||||
@SuppressLint("AddJavascriptInterface")
|
||||
public void setMessagingEnabled(boolean enabled) {
|
||||
if (messagingEnabled == enabled) {
|
||||
return;
|
||||
@@ -519,6 +522,21 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
view.getSettings().setJavaScriptEnabled(enabled);
|
||||
}
|
||||
|
||||
@ReactProp(name = "cacheEnabled")
|
||||
public void setCacheEnabled(WebView view, boolean enabled) {
|
||||
if (enabled) {
|
||||
Context ctx = view.getContext();
|
||||
if (ctx != null) {
|
||||
view.getSettings().setAppCachePath(ctx.getCacheDir().getAbsolutePath());
|
||||
view.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
|
||||
view.getSettings().setAppCacheEnabled(true);
|
||||
}
|
||||
} else {
|
||||
view.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
|
||||
view.getSettings().setAppCacheEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactProp(name = "androidHardwareAccelerationDisabled")
|
||||
public void setHardwareAccelerationDisabled(WebView view, boolean disabled) {
|
||||
if (disabled) {
|
||||
|
||||
Reference in New Issue
Block a user