How to have source instead of html in WebView in React Native

本小妞迷上赌 提交于 2021-02-06 13:58:05

问题


Recently, React Native has deprecated html and url props and replaced them with source.

<WebView
    automaticallyAdjustContentInsets={false}
    contentInset={{top: 0, right: 0, bottom: 0, left: 0}}
    html={"<style>*{margin:0;padding:0;}canvas{position:absolute;transform:translateZ(0);}</style><canvas></canvas><script>var canvas = document.querySelector('canvas');(" + renderString + ").call(" + contextString + ", canvas);</script>"}
    opaque={false}
    underlayColor={'transparent'}
    style={this.props.style}
    javaScriptEnabled={true}
/>

How to replace the html with source. Just replacing doesn't do the trick. Thanks in advance.


回答1:


<WebView source={{ html: "<h1>Hello</h1>" }} />

Documentation available here: http://facebook.github.io/react-native/docs/webview.html#content




回答2:


Have you upgraded React Native version? It is deprecated on newer versions, check the documentation. If you are using older version of React Native, you should use html instead of source.



来源:https://stackoverflow.com/questions/35741853/how-to-have-source-instead-of-html-in-webview-in-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!