I want to open a webpage in React native Webview and the hrefs (links) to be opened in the default browser. I tried using the stopLoading method of Webview but it freezes the view. I successfully achieved this using the answer on this thread.
The method stopLoading of react-native-webview causes the website to freeze
But in some cases, randomly, Upon click of href link, it opens the webpage in the Webview as well beside opening it in the default browser. I want it to be opened in the brwoser only. Please check what's I am doing wrong here. Or is there any better approach to achieve this?
Here is the code I am using:
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 }}
/>
);
}