如何在React Native的WebView中使用源代码而不是html
最近,React Native已经弃用了如何在React Native的WebView中使用源代码而不是html,webview,react-native,Webview,React Native,最近,React Native已经弃用了html和url道具,并将它们替换为source <WebView automaticallyAdjustContentInsets={false} contentInset={{top: 0, right: 0, bottom: 0, left: 0}} html={"<style>*{margin:0;padding:0;}canvas{position:absolute;transform:translate
html
和url
道具,并将它们替换为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}
/>
<WebView source={{ html: "<h1>Hello</h1>" }} />
如何将
html
替换为source
。只是更换并不能奏效。提前感谢。您是否升级了React本机版本?
它在较新版本上已被弃用,请查看文档。如果您使用的是旧版本的React Native,则应使用html
而不是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}
/>
<WebView source={{ html: "<h1>Hello</h1>" }} />
此处提供的文档:只想提到,在React-Native的最新版本中,您还应该添加“originWhitelist”属性,以便html源代码正常工作。。。像这样: