使场景在其他选项卡中可用 - React Native Router Flux
Make scene available in other tabs - React Native Router Flux
我的标签栏设置如下:
<Router>
<Stack key="root">
<Scene
key="tabbar"
tabs
tabBarStyle={styles.tabBar}
>
<Scene
key="home"
title="HOME"
>
<Scene
key="home"
component={Home}
/>
<Scene
key="audioPlayer"
component={AudioPlayer}
title="AUDIO PLAYER"
/>
<Scene
key="notification"
component={Notification}
title="NOTIFICATIONS"
/>
<Scene
key="search"
component={Search}
title="SEARCH"
/>
</Scene>
<Scene
key="latest"
title="LATEST"
component={Latest}
/>
<Scene
key="offline"
component={Offline}
title="OFFLINE"
/>
<Scene
key="more"
component={More}
title="MORE"
/>
</Scene>
</Stack>
</Router>
案例:
我有 4 个标签,分别命名为:首页、最新、离线及更多。
我可以从“主页”选项卡轻松导航到 audioPlayer 场景。
Actions.audioPlayer();
因为我在 Home 选项卡场景中添加了 audioPlayer 场景。
问题:
如何从最新的场景导航到Home场景里面的那个audioPlayer场景?
任何建议。
我是否必须在 Latest 场景中添加 audioPlayer 场景以进行导航?
谢谢。
P.S:我不想将 audioPlayer 场景放入我的最新选项卡中。
我不知道这是否是唯一的解决方案。
更新:
如果我这样做,
Actions.audioPlayer();
我从最新的选项卡导航到主页选项卡,然后从那里导航到音频播放器场景。
我想在“最新”选项卡中使用该导航。 :)
更新 2:
如果我将 audioPlayer 场景放在 tabbar 之外。我可以像我想要的那样导航到 audioPlayer 场景。
但是我遇到了一个问题。
我怎样才能在那个 audioPlayer 场景中获得底部的标签栏?
根据您的第二次更新(将 audioPlayer 场景放在选项卡之外),在将道具 clone
添加到 AudioPlayer 场景时尝试该方法。
<Scene
key="audioPlayer"
component={AudioPlayer}
title="AUDIO PLAYER"
clone
/>
编辑:解释克隆的作用
来自文档
Scenes marked with clone will be treated as templates and cloned into the current scene's parent when pushed.
这意味着推送的场景 audioPlayer
将使用父选项卡场景作为模板呈现,从而呈现选项卡按钮。
我的标签栏设置如下:
<Router>
<Stack key="root">
<Scene
key="tabbar"
tabs
tabBarStyle={styles.tabBar}
>
<Scene
key="home"
title="HOME"
>
<Scene
key="home"
component={Home}
/>
<Scene
key="audioPlayer"
component={AudioPlayer}
title="AUDIO PLAYER"
/>
<Scene
key="notification"
component={Notification}
title="NOTIFICATIONS"
/>
<Scene
key="search"
component={Search}
title="SEARCH"
/>
</Scene>
<Scene
key="latest"
title="LATEST"
component={Latest}
/>
<Scene
key="offline"
component={Offline}
title="OFFLINE"
/>
<Scene
key="more"
component={More}
title="MORE"
/>
</Scene>
</Stack>
</Router>
案例:
我有 4 个标签,分别命名为:首页、最新、离线及更多。
我可以从“主页”选项卡轻松导航到 audioPlayer 场景。
Actions.audioPlayer();
因为我在 Home 选项卡场景中添加了 audioPlayer 场景。
问题:
如何从最新的场景导航到Home场景里面的那个audioPlayer场景?
任何建议。 我是否必须在 Latest 场景中添加 audioPlayer 场景以进行导航?
谢谢。
P.S:我不想将 audioPlayer 场景放入我的最新选项卡中。 我不知道这是否是唯一的解决方案。
更新:
如果我这样做,
Actions.audioPlayer();
我从最新的选项卡导航到主页选项卡,然后从那里导航到音频播放器场景。
我想在“最新”选项卡中使用该导航。 :)
更新 2:
如果我将 audioPlayer 场景放在 tabbar 之外。我可以像我想要的那样导航到 audioPlayer 场景。 但是我遇到了一个问题。 我怎样才能在那个 audioPlayer 场景中获得底部的标签栏?
根据您的第二次更新(将 audioPlayer 场景放在选项卡之外),在将道具 clone
添加到 AudioPlayer 场景时尝试该方法。
<Scene
key="audioPlayer"
component={AudioPlayer}
title="AUDIO PLAYER"
clone
/>
编辑:解释克隆的作用
来自文档
Scenes marked with clone will be treated as templates and cloned into the current scene's parent when pushed.
这意味着推送的场景 audioPlayer
将使用父选项卡场景作为模板呈现,从而呈现选项卡按钮。