我想使用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 Version:0.37.0 Android Studio版本:2.2.2
答案 0 :(得分:0)
我们在代码中发现错误: 此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;
}
}