You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using react-native-webview@13.8.4 and found an issue with the injectedJavaScriptObject prop when used together with the textZoom prop. If both props are set, injectedJavaScriptObject stops working. But, when textZoom is not used, injectedJavaScriptObject works just fine.
<WebView
source={{
uri: url,
}}
onNavigationStateChange={handleWebViewNavigationStateChange}
onMessage={onMessage}
textZoom={100}
injectedJavaScript={injectedJavaScript} // works
injectedJavaScriptObject={{ key: 'value' }} // not working with textZoom prop
/>
On the website side, I'm getting undefined as a result when calling window.ReactNativeWebView.injectedObjectJson().
I started looking into the library's code and found out that when calling the setInjectedJavaScriptObject method, the expression getSettings().getJavaScriptEnabled() returns false if we pass textZoom prop. That's why the logic does not execute. However, if we don't pass textZoom, it returns true and everything works as expected.
// android/src/main/java/com/reactnativecommunity/webview/RNCWebView.java
public void setInjectedJavaScriptObject(String obj) {
if (getSettings().getJavaScriptEnabled()) {
RNCWebViewBridge b = createRNCWebViewBridge(this);
b.setInjectedObjectJson(obj);
}
}
I solved the problem by explicitly setting settings.javaScriptEnabled = true in the default settings:
diff --git a/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt b/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt
index 6a48a81..cee263c 100644
--- a/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt+++ b/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt@@ -72,6 +72,8 @@ class RNCWebViewManagerImpl {
context.addLifecycleEventListener(webView)
mWebViewConfig.configWebView(webView)
val settings = webView.settings
+ // Fixes working injectedJavaScriptObject prop together with textZoom prop in WebView component+ settings.javaScriptEnabled = true
settings.builtInZoomControls = true
settings.displayZoomControls = false
settings.domStorageEnabled = true
Hi! 馃憢
Firstly, thanks for your work on this project! 馃檪
I'm using
react-native-webview@13.8.4
and found an issue with theinjectedJavaScriptObject
prop when used together with thetextZoom
prop. If both props are set,injectedJavaScriptObject
stops working. But, whentextZoom
is not used,injectedJavaScriptObject
works just fine.On the website side, I'm getting
undefined
as a result when callingwindow.ReactNativeWebView.injectedObjectJson()
.I started looking into the library's code and found out that when calling the
setInjectedJavaScriptObject
method, the expressiongetSettings().getJavaScriptEnabled()
returnsfalse
if we passtextZoom
prop. That's why the logic does not execute. However, if we don't passtextZoom
, it returnstrue
and everything works as expected.I solved the problem by explicitly setting
settings.javaScriptEnabled = true
in the default settings:This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered: