Add Android support for beforeContentLoaded
This commit is contained in:
parent
b482bbd3a3
commit
f6e406f969
|
@ -400,6 +400,11 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||||
((RNCWebView) view).setInjectedJavaScript(injectedJavaScript);
|
((RNCWebView) view).setInjectedJavaScript(injectedJavaScript);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ReactProp(name = "injectedJavaScriptBeforeContentLoaded")
|
||||||
|
public void setInjectedJavaScriptBeforeContentLoaded(WebView view, @Nullable String injectedJavaScriptBeforeContentLoaded) {
|
||||||
|
((RNCWebView) view).setInjectedJavaScriptBeforeContentLoaded(injectedJavaScriptBeforeContentLoaded);
|
||||||
|
}
|
||||||
|
|
||||||
@ReactProp(name = "messagingEnabled")
|
@ReactProp(name = "messagingEnabled")
|
||||||
public void setMessagingEnabled(WebView view, boolean enabled) {
|
public void setMessagingEnabled(WebView view, boolean enabled) {
|
||||||
((RNCWebView) view).setMessagingEnabled(enabled);
|
((RNCWebView) view).setMessagingEnabled(enabled);
|
||||||
|
@ -753,6 +758,9 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||||
super.onPageStarted(webView, url, favicon);
|
super.onPageStarted(webView, url, favicon);
|
||||||
mLastLoadFailed = false;
|
mLastLoadFailed = false;
|
||||||
|
|
||||||
|
RNCWebView reactWebView = (RNCWebView) webView;
|
||||||
|
reactWebView.callInjectedJavaScriptBeforeContentLoaded();
|
||||||
|
|
||||||
dispatchEvent(
|
dispatchEvent(
|
||||||
webView,
|
webView,
|
||||||
new TopLoadingStartEvent(
|
new TopLoadingStartEvent(
|
||||||
|
@ -1011,6 +1019,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||||
protected static class RNCWebView extends WebView implements LifecycleEventListener {
|
protected static class RNCWebView extends WebView implements LifecycleEventListener {
|
||||||
protected @Nullable
|
protected @Nullable
|
||||||
String injectedJS;
|
String injectedJS;
|
||||||
|
protected @Nullable
|
||||||
|
String injectedJSBeforeContentLoaded;
|
||||||
protected boolean messagingEnabled = false;
|
protected boolean messagingEnabled = false;
|
||||||
protected @Nullable
|
protected @Nullable
|
||||||
String messagingModuleName;
|
String messagingModuleName;
|
||||||
|
@ -1105,6 +1115,10 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||||
injectedJS = js;
|
injectedJS = js;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setInjectedJavaScriptBeforeContentLoaded(@Nullable String js) {
|
||||||
|
injectedJSBeforeContentLoaded = js;
|
||||||
|
}
|
||||||
|
|
||||||
protected RNCWebViewBridge createRNCWebViewBridge(RNCWebView webView) {
|
protected RNCWebViewBridge createRNCWebViewBridge(RNCWebView webView) {
|
||||||
return new RNCWebViewBridge(webView);
|
return new RNCWebViewBridge(webView);
|
||||||
}
|
}
|
||||||
|
@ -1156,9 +1170,19 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||||
injectedJS != null &&
|
injectedJS != null &&
|
||||||
!TextUtils.isEmpty(injectedJS)) {
|
!TextUtils.isEmpty(injectedJS)) {
|
||||||
evaluateJavascriptWithFallback("(function() {\n" + injectedJS + ";\n})();");
|
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) {
|
public void onMessage(String message) {
|
||||||
ReactContext reactContext = (ReactContext) this.getContext();
|
ReactContext reactContext = (ReactContext) this.getContext();
|
||||||
RNCWebView mContext = this;
|
RNCWebView mContext = this;
|
||||||
|
|
Loading…
Reference in New Issue