0

When I using react-native-webview, I have to set function shouldOverideUrlLoading return false. So that my script in HTML can't listen to the message I send from my Component. It worked fine in iOS but Android my function addEventListener in HTML doesn't trigger anything

My HTML javascript looks like:

console.log("checkme; data", data);
            if (data.data) {
                alert("checkMe:" + JSON.stringify(data.data));
                symbol = data.data;
            }
            // initOnReady();
        })

In my Component I fire postMessage to my WebView like this: this.WebView.postMessage("hello");

In iOS, nothing wrong, but in Android, maybe shouldOverideUrlLoading stopping me to pass data from component to webview to update HTML file. So do you have another solution to pass data from component to webview, not by postMessage or I'm wrong in something? Please help me out

Kakata Kyun
  • 573
  • 1
  • 5
  • 12

1 Answers1

0

I have to customize react-native-webview to resolve this issue. This is function I have to modify in RNCWebviewManager.java

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
  String FILE_LOCAL_PATH = "file:///";
  if (url.contains(FILE_LOCAL_PATH)){ // kyun: Fix allow another HTML file load through 1 first HTML 
    return false;
  }
  dispatchEvent(
    view,
    new TopShouldStartLoadWithRequestEvent(
      view.getId(),
      createWebViewEvent(view, url)));
  return true;
}
Simas Joneliunas
  • 2,890
  • 20
  • 28
  • 35
Kakata Kyun
  • 573
  • 1
  • 5
  • 12