问题
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