简体   繁体   English

React Navigation:嵌套堆栈和选项卡导航器

[英]React Navigation: nesting stack and tab navigator

I have a TabNavigator inside a StackNavigator .我在StackNavigator有一个TabNavigator I cannot define headers inside the different classes that are within the Tabs themself as the TabNavigator has no header (that I know of).由于TabNavigator没有标题(我知道),因此我无法在选项卡本身内的不同类中定义标题。 So I tried to define the it when initializing the StackNavigator .所以我尝试在初始化StackNavigator时定义它。 A button appears on top, but pressing it gives an error for redirecting to an undefined place.一个按钮出现在顶部,但按下它会出现重定向到未定义位置的错误。 probably the this.props.navigator.navigate part contains the mistake, with the this not referring to what I want it to refer to, but I can't find the right syntax anywhere.可能this.props.navigator.navigate部分包含错误, this不是指我想要它指的内容,但我在任何地方都找不到正确的语法。

const NestedNavigator = createBottomTabNavigator ({
  "route1" : {screen : Screen1,
  },
  "route2" : Screen2,
  "route3" : Screen3
  }, 
);

const Navigator = createStackNavigator ({
  "routeA" : ScreenA,
  "routeB" : {
    screen : NestedNavigator, 
    navigationOptions: { headerRight: (<Button title="home" onPress={() => this.props.navigation.navigate("routeC")}/>)}},
  "routeC" : ScreenB},
  {
    initialRouteName: "routeA",
  }
);

navigationOptions is a static property of the component, this does not refer to an instance of the component and therefore no props are available. navigationOptions是组件的静态属性,它不引用组件的实例,因此没有可用的道具。 Instead, if we make navigationOptions a function then React Navigation will call it with an object containing { navigation, navigationOptions, screenProps } -- in this case, all we care about is navigation , which is the same object that is passed to your screen props as this.props.navigation .相反,如果我们让navigationOptions成为一个函数,那么 React Navigation 将使用一个包含{ navigation, navigationOptions, screenProps }的对象调用它——在这种情况下,我们只关心navigation ,它是传递给你的屏幕道具的同一个对象作为this.props.navigation

navigationOptions = ({ navigation }) => { 
  return {
    headerRight: <Button title="home" onPress={() => 
                   navigation.navigate("routeC")}/>
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 反应导航:切换导航器内的嵌套堆栈导航器和选项卡导航器产生2个标头 - React-navigation: nesting stack navigator and tab navigator inside switch navigator results in 2 headers React Navigation:在堆栈导航器中如何禁用选项卡导航器滑动 - React Navigation:How to disable tab navigator swipe when in a stack navigator 反应导航器 5; 选项卡导航器和堆栈导航器 - React Navigator 5; Tab Navigator and Stack Navigator React navigation 5 从堆栈导航器中隐藏标签栏 - React navigation 5 hide tab bar from stack navigator 用于堆栈导航器的 React Navigation 5 canGoBack() - React navigation 5 canGoBack() for stack navigator 带有选项卡导航器的堆栈导航器(React Native) - Stack Navigator with Tab Navigator (React Native) 嵌套在堆栈导航器中的 React Native 选项卡导航器 - React Native tab navigator nested in stack navigator React Navigation 中的选项卡导航器图标 - Tab navigator icons in React Navigation React Navigation:如何使用子堆栈中的特定选项卡返回到根选项卡导航器 - React Navigation: How to go back to root Tab Navigator with specific tab from child stack 如何将多个导航器相互嵌套? 即在抽屉导航器中嵌套底部选项卡并将抽屉导航器嵌套到堆栈导航器 - How to nest multiple navigator within each other? i.e. nesting bottom tab in drawer navigator and nesting drawer navigator to stack navigator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM