我想在 React 本机 Webview 中打开一个网页,并在默认浏览器中打开 href(链接)。我尝试使用 Webview 的 stopLoading 方法,但它冻结了视图。我使用这个线程上的答案成功地实现了这一点。
react-native-webview的方法stopLoading导致网站卡死
但在某些情况下,随机点击 href 链接后,除了在默认浏览器中打开网页外,它还会在 Webview 中打开网页。我希望它只在浏览器中打开。请检查我在这里做错了什么。或者有没有更好的方法来实现这一点?
这是我正在使用的代码:
LoadingIndicatorView() {
return (
<ActivityIndicator
color="#009b88"
size="large"
style={{ flex: 1, justifyContent :'center', }}
/>
);
}
handleWebViewRequest = request => {
const {url} = request;
Linking.openURL(url);
return false;
}
render() {
let uri = 'https://www.google.com/';
let sku = this.props.route.params.sku;
let location = this.props.route.params.location;
return (
<WebView
ref={ref => (this.webview = ref)}
source={{ uri: uri, method: 'POST', body: 'device=tablet&search='+sku+'&ref='+location }}
renderLoading={this.LoadingIndicatorView}
startInLoadingState={true}
onShouldStartLoadWithRequest={this.handleWebViewRequest.bind(this)}
style={{ flex: 1 }}
/>
);
}