微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

更新时移除了 React Native WebView 注入Javascript 代码

如何解决更新时移除了 React Native WebView 注入Javascript 代码

以下代码生成一个应用 js 脚本的 WebView,然后它消失,就像 WebView 在更新时重新加载一样。所以你看到蓝色的闪光然后页面回到初始状态。有人遇到过类似的问题吗?

export default class NewComponent extends Component {
  constructor(props) {
    super(props)
    this.webView = createRef()
  }

componentDidMount() {

    this.webView.current.injectJavaScript(
      `document.body.style.backgroundColor = 'blue';
      true;`
    )
  }

render() {
   

    return (
      <View>
        <WebView
          ref={this.webView}
          source={{uri: this.props.mapUrl.url}}
          originWhitelist={['*']}
          javaScriptEnabled={true}
          scrollEnabled={false}
          bounces={false}
        />
      </View>
    )
  }
}

我正在物理 android 设备上进行测试。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。