说明
我想使用 React Native WebView 进行"与现有 Android 应用程序的集成",但它没有加载源代码。而且它不会调用WebView的onLoad
,onLoadStart
,onError
。
重现步骤和示例代码
render() {
let { url, headers, html } = this.props;
if (!!url && !/^[a-zA-Z-_]+:/.test(url))
{
url = 'http://' + url;
}
if (html)
{
html = '<!DOCTYPE html><html><body>'+html+'</body></html>'
}
console.log(html);
const source = !!url ? {uri: url} : {html: html}
console.log(source);
return (
<View style={{flex: 1}}>
<WebView
style={{flex: 1}}
source={source}
javaScriptEnabled={true}
domStorageEnabled={true}
decelerationRate="normal"
automaticallyAdjustContentInsets={false}
onNavigationStateChange={this._onNavigationStateChange}
onShouldStartLoadWithRequest={this._onShouldStartLoadWithRequest}
startInLoadingState={!!url}
scalesPageToFit={true}
renderError={()=>{
return (
<View></View>
)
}}
/>
</View>
);
}
我找到了两个,但它们没有解决我的问题:
- React
- Native Webview未加载任何url(React Native Web视图不起作用(
- React Native WebView 未加载源代码
#
反应原生版本:0.37.0安卓工作室版本:2.2.2
我们在代码中发现了一个错误:此 custrom 视图的类名涵盖 React Native 类名
public class CustomImageView extends SimpleViewManager<ImageView> {
// Error: This class name: RCTWebView cover React Native class name
public static final String REACT_CLASS = "RCTWebView";
@Override
public String getName() {
return REACT_CLASS;
}
}