Skip to content

Webview can't call onLoad's callback when source is HTML source code in iOS, but, it'ok for Android. #14550

Closed
@rogerluo410

Description

@rogerluo410

-- Please use this template, and delete everything above this line before submitting your issue ---

Description

The Webview's source is HTML code, will inject JS while onLoad callback executed. This is ok for Android, but, for iOS, the onLoad's callback is even NOT called...

       constructor() {
         super()
        this.webView = null
        this.injectJavaScript = this.injectJavaScript.bind(this)
       }

       injectJavaScript() {
         alert(1);   // Even not walk here
         const bridgeJS = `
           document.addEventListener("message", function(event) {
                window.scrollTo(0, event.data);
           }, false);

          window.addEventListener("message", function(event) {
            window.scrollTo(0, event.data);
          }, false);
        `
         if (this.webView) {
           this.webView.injectJavaScript(bridgeJS)
        }
      }
      <WebView
          ref={ webView => this.webView = webView}
          source={ {html: ' <html><body><div style="height: 3000px;">13232</div></body></html>'} }
          javaScriptEnabled={true}
          domStorageEnabled={true}
          onMessage={this._onMessage}
          onLoad={this.injectJavaScript}
          />

this code works well on Android, but, even NOT call onLoad to inject JavaScript in iOS...
Meanwhile, if I put the HTML to local directory, and use another approach to direct the source like
source={ require('../xxx.html') } is work fine on iOS.

Solution

I want to know why even NOT call onLoad's callback when set source: {html: '...'} in iOS.

But, it's ok for Android with same code...

Help me, thanks!

Additional Information

React Native version: 0.44.2
Platform: iOS / Android
Operating System: MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Ran CommandsOne of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions