This commit is contained in:
parent
07bd00e4e1
commit
9e11b162cb
|
@ -102,6 +102,8 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
/**
|
||||
* Manages instances of {@link WebView}
|
||||
* <p>
|
||||
|
@ -283,6 +285,23 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||
view.setVerticalScrollBarEnabled(enabled);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <O> Object invokeMethodIfExists(final O o, final String methodName, Object... args) {
|
||||
Method[] methods = o.getClass().getMethods();
|
||||
for (Method method : methods) {
|
||||
if (method.getName().equals(methodName)) {
|
||||
try {
|
||||
method.invoke(o, args);
|
||||
} catch (IllegalAccessException e) {
|
||||
return null;
|
||||
} catch (InvocationTargetException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ReactProp(name = "cacheEnabled")
|
||||
public void setCacheEnabled(WebView view, boolean enabled) {
|
||||
if (enabled) {
|
||||
|
@ -290,13 +309,14 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||
if (ctx != null) {
|
||||
//view.getSettings().setAppCachePath(ctx.getCacheDir().getAbsolutePath());
|
||||
//view.getSettings().setAppCacheEnabled(true);
|
||||
Util.invokeMethodIfExists(view.getSettings(), "setAppCachePath", ctx.getCacheDir().getAbsolutePath());
|
||||
RNCWebViewManager.invokeMethodIfExists(view.getSettings(), "setAppCachePath", ctx.getCacheDir().getAbsolutePath());
|
||||
view.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
|
||||
Util.invokeMethodIfExists(view.getSettings(), "setAppCacheEnabled", true);
|
||||
RNCWebViewManager.invokeMethodIfExists(view.getSettings(), "setAppCacheEnabled", true);
|
||||
}
|
||||
} else {
|
||||
view.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
|
||||
view.getSettings().setAppCacheEnabled(false);
|
||||
//view.getSettings().setAppCacheEnabled(false);
|
||||
RNCWebViewManager.invokeMethodIfExists(view.getSettings(), "setAppCacheEnabled", false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue