V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
ccraohng
V2EX  ›  React

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

  •  
  •   ccraohng · Mar 4, 2020 · 2850 views
    This topic created in 2251 days ago, the information mentioned may be changed or developed.

    如题。

    3 replies    2020-03-05 01:02:56 +08:00
    also24
        1
    also24  
       Mar 5, 2020
    没有写过 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
       Mar 5, 2020 via Android
    @also24
    emmmm
    它提供的 bottom-tab 组件生成栈,并不能具有类似 switchTab 切换功能。可以对比微信和谷歌商店的 tab 导航切换。
    ccraohng
        3
    ccraohng  
    OP
       Mar 5, 2020 via Android
    结贴吧。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   825 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 20:13 · PVG 04:13 · LAX 13:13 · JFK 16:13
    ♥ Do have faith in what you're doing.