最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React Native Router Flux: navigate from main scene to child - Stack Overflow

programmeradmin1浏览0评论

Version

  • react-native-router-flux v3.35.0
  • react-native v0.31

I have few scenes. one of scenes have few sub-scenes. how can i navigate to one of sub-scenes from one of main scenes?

Example :

<Router createReducer={reducerCreate} getSceneStyle={getSceneStyle}>
        <Scene key="root">
          <Scene key="login" direction="vertical" component={Login} title="Login" hideTabBar hideNavBar />
          <Scene key="tabbar" initial={show}>
            <Scene key="main" tabs tabBarStyle={styles.tabBarStyle} tabBarSelectedItemStyle={styles.tabBarSelectedItemStyle} tabBarIconContainerStyle={styles.tabBarIconContainerStyle} >
              <Scene key="courses" component={Courses} title="Courses" icon={IconCourses} navigationBarStyle={styles.navigationBarStyle} titleStyle={styles.titleStyle} initial />
              <Scene key="register"  component={Register} title="Register" icon={IconRegister} navigationBarStyle={styles.navigationBarStyle} titleStyle={styles.titleStyle} />
              <Scene key="schedule" component={Schedule} title="Schedule" icon={IconSchedule} navigationBarStyle={styles.navigationBarStyle} titleStyle={styles.titleStyle} />
              <Scene key="evaluation" component={Schedule} title="Evaluation" icon={IconEvaluation} navigationBarStyle={styles.navigationBarStyle} titleStyle={styles.titleStyle} />
              <Scene key="profile"
              component={Profile}
              title="Profile"
              icon={IconProfile}
              navigationBarStyle={styles.navigationBarStyle}
              titleStyle={styles.titleStyle}
              onLeft={() => { Actions.login(); }}
              leftTitle="Add Account"
              onRight={() => { Actions.login({type: 'reset'}); }}
              rightTitle="Logout"
              rightButtonTextStyle={styles.ButtonTextStyle}
              leftButtonTextStyle={styles.ButtonTextStyle}
              leftButtonStyle={styles.leftButtonStyle} />
            </Scene>
          </Scene>
          <Scene key="terms" component={Terms} />
          <Scene key="details" component={Details} title="Details" navigationBarStyle={styles.navigationBarStyle} titleStyle={styles.titleStyle} backButtonTextStyle={styles.backButtonTextStyle} hideTabBar />
        </Scene>
      </Router>

I want to navigate from Details to Courses. but courses is a Tab under another. how can i do that?

I can navigate only to tabbar scene, not courses or register.

Version

  • react-native-router-flux v3.35.0
  • react-native v0.31

I have few scenes. one of scenes have few sub-scenes. how can i navigate to one of sub-scenes from one of main scenes?

Example :

<Router createReducer={reducerCreate} getSceneStyle={getSceneStyle}>
        <Scene key="root">
          <Scene key="login" direction="vertical" component={Login} title="Login" hideTabBar hideNavBar />
          <Scene key="tabbar" initial={show}>
            <Scene key="main" tabs tabBarStyle={styles.tabBarStyle} tabBarSelectedItemStyle={styles.tabBarSelectedItemStyle} tabBarIconContainerStyle={styles.tabBarIconContainerStyle} >
              <Scene key="courses" component={Courses} title="Courses" icon={IconCourses} navigationBarStyle={styles.navigationBarStyle} titleStyle={styles.titleStyle} initial />
              <Scene key="register"  component={Register} title="Register" icon={IconRegister} navigationBarStyle={styles.navigationBarStyle} titleStyle={styles.titleStyle} />
              <Scene key="schedule" component={Schedule} title="Schedule" icon={IconSchedule} navigationBarStyle={styles.navigationBarStyle} titleStyle={styles.titleStyle} />
              <Scene key="evaluation" component={Schedule} title="Evaluation" icon={IconEvaluation} navigationBarStyle={styles.navigationBarStyle} titleStyle={styles.titleStyle} />
              <Scene key="profile"
              component={Profile}
              title="Profile"
              icon={IconProfile}
              navigationBarStyle={styles.navigationBarStyle}
              titleStyle={styles.titleStyle}
              onLeft={() => { Actions.login(); }}
              leftTitle="Add Account"
              onRight={() => { Actions.login({type: 'reset'}); }}
              rightTitle="Logout"
              rightButtonTextStyle={styles.ButtonTextStyle}
              leftButtonTextStyle={styles.ButtonTextStyle}
              leftButtonStyle={styles.leftButtonStyle} />
            </Scene>
          </Scene>
          <Scene key="terms" component={Terms} />
          <Scene key="details" component={Details} title="Details" navigationBarStyle={styles.navigationBarStyle} titleStyle={styles.titleStyle} backButtonTextStyle={styles.backButtonTextStyle} hideTabBar />
        </Scene>
      </Router>

I want to navigate from Details to Courses. but courses is a Tab under another. how can i do that?

I can navigate only to tabbar scene, not courses or register.

Share Improve this question asked Aug 29, 2016 at 12:50 Ata MohammadiAta Mohammadi 3,5506 gold badges43 silver badges71 bronze badges 1
  • Did you try Actions.create to create the scenes prior to the render and pass it to the Router scenes prop? Also, try disabling any 'initial' props as that was causing issues for me. What issue did you have with the Switch? I had a lot of trouble but sorted it out... A trick that helped me force re-renders when Switch changed was setting Router key to something including part of the Switch state... ie authenticated vs guest... Make sure to change the key when the Switch changes. And don't forget about Actions.refresh. Seems hacky to me but seems to be used a lot as 'escape hatch'. – Travis White Commented Dec 15, 2016 at 5:45
Add a comment  | 

2 Answers 2

Reset to default 19

I've found that you can switch to inner tabs if you navigate to the tabbar first, e.g.:

<Button onPress={() => {
    Actions.tabbar({type:ActionConst.RESET});
    Actions.courses();
}} title="See Courses" />

The first scene transition resets the scene to your tab bar, and would by default show your initial scene, the second transition then replaces your current scene due to how react-native-router-flux handles tab scene transitions.

I actually answered a very similar question here. The problem is that from the context of login you'd have access to Actions.tabbar and it would then route you to either a nested scene with the initial prop set to true, or the first nested scene in the stack. To see an example of what I am talking about refer to the link I included in the first line of this answer.

Hope this helps! :)

发布评论

评论列表(0)

  1. 暂无评论