Search code examples
reactjsreact-nativereact-routerreact-native-router-flux

React Native Router Flux - Navigating to scene and back - conflicts with another child


I am using react-native-router-flux and am having an issue navigating between scenes and it's driving me crazy!

This is my Router:

<Router navigationBarStyle={styles.navigationBody} titleStyle={styles.navigationTitle} duration={0} >
    <Scene key="root">
      <Scene key="addNode" component={HA_AddNode} socket={socket} rooms={["Living Room", "Master Bedroom", "Hall", "Office"]} nodes ={["Light Switch", "Socket"]} title="Add Node" backTitle="Back" backButtonTextStyle={{color: 'white'}} backButtonImage={require('./images/back_arrow_icon.png')} onLeft={()=> Actions.pop()} />
      <Scene key="addRoom" component={HA_AddRoom} socket={socket} locations={["Downstairs", "Upstairs"]} title="Add Room" backTitle="Back" backButtonTextStyle={{color: 'white'}} backButtonImage={require('./images/back_arrow_icon.png')} onLeft={()=> Actions.pop()} />
      <Scene key="tabBar" tabs style={styles.tabBar} initial={true}>
        <Scene key='dashboard' component={HA_Dashboard} title='Dashboard' initial={true} icon={HA_TabIcon} iconTitle="ios-home-outline" />
        <Scene key='rooms' component={HA_Rooms} title='Rooms' icon={HA_TabIcon} iconTitle="ios-list-box-outline" />
        <Scene key='settings' component={HA_Settings} title='Settings' icon={HA_TabIcon} iconTitle="ios-settings-outline" />
      </Scene>
    </Scene>
  </Router>

What am I trying to achieve is when I have pressed a button, after X seconds it navigates from the addRoom scene (which is accessed via link on the settings page) to the rooms tab scene. I am doing this with the following code:

timer.setTimeout(this, 'roomsNavigate', () => Actions.rooms(), 2500);

That works fine and navigates to the rooms page correctly.

Now the issue is that if I go back the settings page and click on the link to take me to the add room page then I get the following error:

navigationState.children[2].key "scene_addRoom_1_addRoom" conflicts withanother child!

I have also noticed that if I click on any other links on the settings page then it is taking me to the add room page and not its correct page.

How can I go about fixing this?


Solution

  • <Router navigationBarStyle={styles.navigationBody} titleStyle={styles.navigationTitle} duration={0} >
        <Scene key="root">
          <Scene key="addNode" component={HA_AddNode} socket={socket} rooms={["Living Room", "Master Bedroom", "Hall", "Office"]} nodes ={["Light Switch", "Socket"]} title="Add Node" backTitle="Back" backButtonTextStyle={{color: 'white'}} backButtonImage={require('./images/back_arrow_icon.png')} onLeft={()=> Actions.pop()} />
          <Scene key="addRoom" component={HA_AddRoom} socket={socket} locations={["Downstairs", "Upstairs"]} title="Add Room" backTitle="Back" backButtonTextStyle={{color: 'white'}} backButtonImage={require('./images/back_arrow_icon.png')} onLeft={()=> Actions.pop()} />
          <Scene key="tabBar" tabs style={styles.tabBar} initial={true}>
            <Scene key='dashboard' component={HA_Dashboard} title='Dashboard' initial={true} icon={HA_TabIcon} iconTitle="ios-home-outline" />
            <Scene key='rooms' component={HA_Rooms} title='Rooms' icon={HA_TabIcon} iconTitle="ios-list-box-outline" />
            <Scene key='settings' component={HA_Settings} title='Settings' icon={HA_TabIcon} iconTitle="ios-settings-outline" />
          </Scene>
        </Scene>
      </Router>
    

    You cannot navigate to dashboard, rooms or settings from addNode or addRoom scenes. You can only navigate to tabBar scenes from them.

    But from dashboard, rooms and settings scenes you can navigate to addNode or addRoom scenes.