Skip to content

Webview component: jsEvaluationValue is undefined in Android #7788

@areina

Description

@areina

Hi,

I'm using a Webview component and trying to define the height of it automatically. For that, I'm using injectedJavaScript and onNavigationStateChange, and it's doesn't work in Android. There is no value for jsEvaluationValue in the event of onNavigationStateChange callback.
This is an extract of the code that I'm using:

var SampleApp = React.createClass({
      getInitialState: function () {
        return {
            webViewHeight: 100 // default height, can be anything
        };
    },
  render: function() {
          var html = '<p><strong>WebView Content</strong></p><ul><li>Foo</li><li>Bar</li><li>Baz</li><\/ul>';
    return (
      <View style={{paddingTop: 20}}>
                <Text>This is above the WebView.</Text>
                <WebView
                    html={html}
                    injectedJavaScript="document.body.scrollHeight;"
                    javaScriptEnabled={true}
                    scrollEnabled={false}
                    onNavigationStateChange={this._updateWebViewHeight}
                    automaticallyAdjustContentInsets={true}
                    style={{height: this.state.webViewHeight}}/>
                <Text>This is below the WebView.</Text>
            </View>
    );
  },
    //called when HTML was loaded and injected JS executed
    _updateWebViewHeight: function (event) {
        //jsEvaluationValue contains result of injected JS
      console.log("jsEvaluationValue: ");
      console.log(event.jsEvaluationValue);
        this.setState({webViewHeight: parseInt(event.jsEvaluationValue)});
    }
});

And here you can check a live example: https://rnplay.org/apps/At-z4A

There you can see how it works properly on iOS but it doesn't work on Android. Locally I'm using Linux, React 15.0.2 and React-Native 0.26.0

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions