[英]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.