美文网首页
react-native 阻止路由返回监听

react-native 阻止路由返回监听

作者: Biao_349d | 来源:发表于2023-10-27 15:08 被阅读0次
    const goBack = (onBack?: () => void) => {
   
        const isSave = true
        const onBackFn = onBack ? onBack : navigation.goBack
        if (!isSave) {
          onBackFn()

          return
        }
        Modal.alert('', <Text>当前内容已修改,是否存为草稿?</Text>, [
          {
            text: '否',
            onPress: () => {
              onBackFn()
            }
          },
          {
            text: '是',
            onPress: () => {
              onSubmitDraft(onBackFn)
            }
          }
        ])
      })
    }

    const navigationBeforeRemove = () => {
      const l = navigation.addListener('beforeRemove', e => {
        console.log(11)
        // Prevent default behavior of leaving the screen
        e.preventDefault()
        // Prompt the user before leaving the screen
        goBack(() => {
          navigation.dispatch(e.data.action)
        })
      })
    }

相关文章

网友评论

      本文标题:react-native 阻止路由返回监听

      本文链接:https://www.haomeiwen.com/subject/zieeidtx.html