【问题标题】:Go to sub-scene tabs - react-native-router-flux转到子场景选项卡 - react-native-router-flux
【发布时间】:2020-01-22 18:42:07
【问题描述】:

这是我的路由器层次结构:

<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>

如果我在Profilo 页面上并且我不会去Vehicle 页面,我使用Actions.vehicle() 但我收到此错误:

Actions.vehicle() 不是函数

我已经尝试过this solution,但这也不起作用 我该如何解决这个问题?

snack 的结果如下:

【问题讨论】:

    标签: react-native expo react-native-router-flux


    【解决方案1】:

    使用动作场景键将要求您的场景与其他场景处于同一级别,即vehicle 场景不能是profile 的子组件。

    此外,您将需要一个Stack 组件来容纳profilevehicle 场景,以便您可以调用Actions.{key} 来正确访问场景。

    我在这里添加了一个snack 供您使用。 :)

    建议的解决方案:

    <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>
    

    【讨论】:

    • 这很奇怪。它正在制作我的世博小吃。使用Stack 组件更新后的代码看起来如何?我可以从那里进行故障排除。
    • 当我打开并启动你的世博小吃时,产生了错误
    • 呃。它不适用于browser。您需要选择AndroidiOS
    • 我在Android 上运行你的零食...在我的问题中,我添加运行你的snack 的结果
    • 好的。我可以在那里看到几个问题。您需要通过将两个场景都包含在 Stack 中来重组场景,并以不同的方式命名。我已经更新了我的答案以包含一个建议的解决方案。
    猜你喜欢
    • 2017-08-19
    • 2017-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-18
    • 1970-01-01
    相关资源
    最近更新 更多