diff --git a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java index ffcabf4..ad1cf07 100644 --- a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +++ b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java @@ -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} *

@@ -283,6 +285,23 @@ public class RNCWebViewManager extends SimpleViewManager { view.setVerticalScrollBarEnabled(enabled); } + @Nullable + public static 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 { 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); } }