出现后,问题在React-Native-WebView上返回False

发布于 2025-02-09 22:30:24 字数 1967 浏览 2 评论 0原文

在我的React-nigation项目中,我使用React-native-webview,实际上,我使用onsh​​oundStartLoadWithRequest来验证URL请求。当URL等于我的变量时,onShoundStartLoadWithRequest返回true并正常加载URL,但是当URL等于我的变量时,我会显示警报和onshoundStartLoadWithRequest返回false。 当用户单击OK时,请在警报处导航,我会从我的应用登录页面导航,但是如果用户取消并留在页面上,请不要加载其他页面上的其他网址 基本上,好像在返回虚假到URL之后,OnShoundStartLoadWithRequest没有加载任何其他

我的代码:

function verifyurl(url) {

    
    if (url == myvarUrl) {
      alerta();
      return false;
    } else {
      setNewUrl(url)
      return true;
    }
  }

  async function alerta() {
    const response = await alert();
    response && logOut();
  }


  //Verifica se existe item na pilha navegação e retira
  function logOut() {
    let canGoBack = navigation.canGoBack();
    canGoBack ? navigation.goBack() : console.log('AGIU MAIS DE UMA VEZ');
  }

  /* ========================> Retorno de Visualização <======================== */

  const Spinner = () => (
    <View style={genericStyles.activityContainer}>
      <ActivityIndicator size="large" color="#f29900" />
    </View>
  );

  return (
    <View style={genericStyles.containerWebView}>
      <StatusBar backgroundColor={genericStyles.colors.BlueBg} barStyle={'light-content'} />
      <WebView
        source={{ uri: propriedade }}
        ref={webViewRef}
        originWhitelist={['*']}
        allowsInlineMediaPlayback
        javaScriptEnabled
        scalesPageToFit
        mediaPlaybackRequiresUserAction={false}
        javaScriptEnabledAndroid
        useWebkit
        startInLoadingState={true}
        cacheEnabled={false}
        renderLoading={Spinner}
        onShouldStartLoadWithRequest={(event) => {
          return verifyurl(event.url)
        }}
      />
    </View>
  )

开发环境

react: ^17.0.2 => 17.0.2
react-native: ^0.68.2 => 0.68.2
react-native-webview: 11.22.2

请帮助我!

In my React-Native project i use react-native-webview, actually i use onShouldStartLoadWithRequest to verify url requests. When url is equals my variable, the onShouldStartLoadWithRequest return true and load url normally, but, when url equals my variable i display alert and onShouldStartLoadWithRequest return false.
On alert when user click in ok i navigate from my app login page, but if user cancel and stay on page the webview dont load others urls ontened of page anymore
Basically, it's as if after returning false to a url, onShouldStartLoadWithRequest didn't load any other

My code:

function verifyurl(url) {

    
    if (url == myvarUrl) {
      alerta();
      return false;
    } else {
      setNewUrl(url)
      return true;
    }
  }

  async function alerta() {
    const response = await alert();
    response && logOut();
  }


  //Verifica se existe item na pilha navegação e retira
  function logOut() {
    let canGoBack = navigation.canGoBack();
    canGoBack ? navigation.goBack() : console.log('AGIU MAIS DE UMA VEZ');
  }

  /* ========================> Retorno de Visualização <======================== */

  const Spinner = () => (
    <View style={genericStyles.activityContainer}>
      <ActivityIndicator size="large" color="#f29900" />
    </View>
  );

  return (
    <View style={genericStyles.containerWebView}>
      <StatusBar backgroundColor={genericStyles.colors.BlueBg} barStyle={'light-content'} />
      <WebView
        source={{ uri: propriedade }}
        ref={webViewRef}
        originWhitelist={['*']}
        allowsInlineMediaPlayback
        javaScriptEnabled
        scalesPageToFit
        mediaPlaybackRequiresUserAction={false}
        javaScriptEnabledAndroid
        useWebkit
        startInLoadingState={true}
        cacheEnabled={false}
        renderLoading={Spinner}
        onShouldStartLoadWithRequest={(event) => {
          return verifyurl(event.url)
        }}
      />
    </View>
  )

Development environment

react: ^17.0.2 => 17.0.2
react-native: ^0.68.2 => 0.68.2
react-native-webview: 11.22.2

Please Help me!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文