V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ccraohng
V2EX  ›  React

问一下 RN 路由相关的一个问题。类似 微信 Bottom Tab 切换到 Tab 导航的时候,按下返回键, 退出 APP。请问 RN 能实现相关功能吗?或者说相关关键字。

  •  
  •   ccraohng · 2020-03-04 23:58:10 +08:00 · 1924 次点击
    这是一个创建于 1485 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如题。

    3 条回复    2020-03-05 01:02:56 +08:00
    also24
        1
    also24  
       2020-03-05 00:21:28 +08:00
    没有写过 React Native,大致翻了一下文档,RN 官方建议使用的导航插件是 React Navigation。

    然后翻看 React Navigation 的文档,似乎找到了解决方式。

    这是标准情况下的处理逻辑,只要空栈就能退出:
    https://reactnavigation.org/docs/nesting-navigators#each-navigator-keeps-its-own-navigation-history

    Each navigator keeps its own navigation history
    For example, when you press the back button inside a nested stack navigator, it'll go back to the previous screen inside the nested stack even if there's another navigator as the parent.


    这是自定义处理 back 键逻辑的方式:
    https://reactnavigation.org/docs/custom-android-back-button-handling
    ccraohng
        2
    ccraohng  
    OP
       2020-03-05 01:01:49 +08:00 via Android
    @also24
    emmmm
    它提供的 bottom-tab 组件生成栈,并不能具有类似 switchTab 切换功能。可以对比微信和谷歌商店的 tab 导航切换。
    ccraohng
        3
    ccraohng  
    OP
       2020-03-05 01:02:56 +08:00 via Android
    结贴吧。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3896 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:17 · PVG 18:17 · LAX 03:17 · JFK 06:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.