web视图单击:未检测到url:React Native

ct2axkht  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(168)

我有一个react原生应用程序,登录后在web视图中加载url。用户在web视图中移动,单击支持的链接。现在,我想通过单击web视图中的按钮从web视图中打开共享选项。当我们点击按钮时,我们有一个url,但我无法检测到带有“onnavigationstatechange”的url。那么,如果没有url,我们如何处理这个问题呢?我尝试了很多链接,但都没有得到结果。从未到达“开放共享控制器”,也未到达“导航类型单击”。以下是我的示例代码:

<WebView scalesPageToFit
    style={{ flex: 1 }} source={{ uri: url  }} onLoadStart={() => (setLoading(true))} onLoadEnd={() => (setLoading(false))}
    javaScriptEnabled={true}
    domStorageEnabled={true}
    onNavigationStateChange = {handleNavigationStateChange}

    onLoadProgress = {({ nativeEvent }) => {

      console.log(nativeEvent.url)     
  }}
    />

const handleNavigationStateChange = navState => {
console.log(navState.url);
console.log(navState.navigationType)
const { url } = navState.url;
if (!url) return;

if (url.includes('Logout')) {
  Alert.alert(
    "Logout",
    "Are you sure you want to logout?",
    [
      {
        text: "No",
        onPress: () => console.log("Cancel Pressed"),
        style: "cancel"
      },
      { text: "Yes", onPress: () => navigation.pop(1) }
    ]
  );
}
if (url.includes('Register')) {
  console.log('OPEN SHARE CONTROLLER')
}
if (navState.navigationType === 'click') {
  // User clicked something
  console.log('User clicked something')

} };

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题