th3g3ntl3man
th3g3ntl3man

Reputation: 2106

Go to sub-scene tabs - react-native-router-flux

This is my hierarchical structure of router:

<Tabs
  key='tabbar'
  backToInitial
  onTabOnPress={() => {
    console.log('Back to initial and also print this');
  }}
  swipeEnabled
  hideNavBar={true}
>
  <Scene
    title='Profilo'
    key='profile'
    component={Profile}
    tabBarLabel='Profilo'
    icon={TabBarIcon}
    name='ios-person'
    titleStyle={{
      fontFamily: 'RobotoRegular', 
      fontSize: 24, 
      color: '#00b0ff'
    }}
  >
    <Scene
      title='adsf'
      key='vehicle'
      component={Vehicle}
      titleStyle={{
        fontFamily: 'RobotoRegular', 
        fontSize: 24, 
        color: '#00b0ff'
      }}
    />
  </Scene>

</Tabs>

If I am on the Profilo page and I wont to go to the Vehicle page, I use Actions.vehicle() but I obtain this error:

Actions.vehicle() is not a function

I already try with this solution, but this also doesn't work How can I resolve this problem?

The Result of a propesed snack is the following: enter image description here

Upvotes: 1

Views: 289

Answers (1)

kenmistry
kenmistry

Reputation: 2143

Using an action scene key will require your scene to be on the same level as your other scenes, i.e. the vehicle scene cannot be a child component of profile.

In addition, you will need a Stack component to house both profile and vehicle scenes so that you can call Actions.{key} to access the scenes properly.

I have included a snack here for you to play with it. :)

Proposed solution:

<Tabs
  key='tabbar'
  backToInitial
  onTabOnPress={() => {
    console.log('Back to initial and also print this');
  }}
  swipeEnabled
  hideNavBar={true}
>
  <Stack
    title='ProfiloStack'
    key='profileStack'
  >
  <Scene
    title='Profilo'
    key='profile'
    component={Profile}
    tabBarLabel='Profilo'
    icon={TabBarIcon}
    name='ios-person'
    titleStyle={{
      fontFamily: 'RobotoRegular', 
      fontSize: 24, 
      color: '#00b0ff'
    }}
  />
    <Scene
      title='adsf'
      key='vehicle'
      component={Vehicle}
      titleStyle={{
        fontFamily: 'RobotoRegular', 
        fontSize: 24, 
        color: '#00b0ff'
      }}
    />
  </Stack>
</Tabs>

Upvotes: 1

Related Questions