如何在React Native的WebView中使用源代码而不是html

如何在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

最近,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: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源代码正常工作。。。像这样: