mirror of
https://github.com/status-im/react-native-webview.git
synced 2026-08-31 03:31:05 +00:00
Add Android support for beforeContentLoaded
This commit is contained in:
@@ -396,6 +396,11 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
((RNCWebView) view).setInjectedJavaScript(injectedJavaScript);
|
||||
}
|
||||
|
||||
@ReactProp(name = "injectedJavaScriptBeforeContentLoaded")
|
||||
public void setInjectedJavaScriptBeforeContentLoaded(WebView view, @Nullable String injectedJavaScriptBeforeContentLoaded) {
|
||||
((RNCWebView) view).setInjectedJavaScriptBeforeContentLoaded(injectedJavaScriptBeforeContentLoaded);
|
||||
}
|
||||
|
||||
@ReactProp(name = "messagingEnabled")
|
||||
public void setMessagingEnabled(WebView view, boolean enabled) {
|
||||
((RNCWebView) view).setMessagingEnabled(enabled);
|
||||
@@ -747,6 +752,9 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
super.onPageStarted(webView, url, favicon);
|
||||
mLastLoadFailed = false;
|
||||
|
||||
RNCWebView reactWebView = (RNCWebView) webView;
|
||||
reactWebView.callInjectedJavaScriptBeforeContentLoaded();
|
||||
|
||||
dispatchEvent(
|
||||
webView,
|
||||
new TopLoadingStartEvent(
|
||||
@@ -1000,6 +1008,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
protected static class RNCWebView extends WebView implements LifecycleEventListener {
|
||||
protected @Nullable
|
||||
String injectedJS;
|
||||
protected @Nullable
|
||||
String injectedJSBeforeContentLoaded;
|
||||
protected boolean messagingEnabled = false;
|
||||
protected @Nullable
|
||||
String messagingModuleName;
|
||||
@@ -1081,6 +1091,10 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
injectedJS = js;
|
||||
}
|
||||
|
||||
public void setInjectedJavaScriptBeforeContentLoaded(@Nullable String js) {
|
||||
injectedJSBeforeContentLoaded = js;
|
||||
}
|
||||
|
||||
protected RNCWebViewBridge createRNCWebViewBridge(RNCWebView webView) {
|
||||
return new RNCWebViewBridge(webView);
|
||||
}
|
||||
@@ -1132,9 +1146,19 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
injectedJS != null &&
|
||||
!TextUtils.isEmpty(injectedJS)) {
|
||||
evaluateJavascriptWithFallback("(function() {\n" + injectedJS + ";\n})();");
|
||||
//evaluateJavascriptWithFallback(injectedJS);
|
||||
}
|
||||
}
|
||||
|
||||
public void callInjectedJavaScriptBeforeContentLoaded() {
|
||||
if (getSettings().getJavaScriptEnabled() &&
|
||||
injectedJSBeforeContentLoaded != null &&
|
||||
!TextUtils.isEmpty(injectedJSBeforeContentLoaded)) {
|
||||
evaluateJavascriptWithFallback("(function() {\n" + injectedJSBeforeContentLoaded + ";\n})();");
|
||||
//evaluateJavascriptWithFallback(injectedJSBeforeContentLoaded);
|
||||
}
|
||||
}
|
||||
|
||||
public void onMessage(String message) {
|
||||
ReactContext reactContext = (ReactContext) this.getContext();
|
||||
RNCWebView mContext = this;
|
||||
|
||||
Reference in New Issue
Block a user