繁体   English   中英

使用 react-native-webview 的 stopLoading 后 Webview 冻结

[英]Webview freezed after using the stopLoading of react-native-webview

我想在 React Native Webview 中打开一个网页,并在默认浏览器中打开 hrefs(链接)。 我尝试使用 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 }}
      />    
    );
  }

我在为onShouldStartLoadWithRequest调用的方法中添加了onShouldStartLoadWithRequest

webViewRef.current.stopLoading();

其中 webViewRef 是 webView 的引用

ref = { webViewRef }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM