我读到这里 ,使用的createStackNavigator作为一个组件类是可能的,而我试图做到这一点,但我总是得到一个错误。
取而代之的是:
export default createStackNavigator({
Messages
}, {
defaultNavigationOptions: {
gesturesEnabled: false
}
})
我尝试这样做:
class MessagesStack extends React.Component {
render() {
const RouteConfigs = {
Messages
};
const NavigatorConfigs = {
defaultNavigationOptions: {
gesturesEnabled: false
}
};
const Stack = createStackNavigator(RouteConfigs, NavigatorConfigs);
return <Stack />;
}
}
export default MessagesStack;
但是,我总是得到这样的错误:
Invariant Violation: Invariant Violation: The navigation prop is missing for this navigator. In react-navigation 3 you must set up your app container directly. More info: https://reactnavigation.org/docs/en/app-containers.html
所以,我试图纠正它,加入导航道具,就像这样:
return <Stack navigation={this.props.navigation} />;
但后来我得到了一个新的错误
TypeError: TypeError: No "routes" found in navigation state. Did you try to pass the navigation prop of a React component to a Navigator child? See https://reactnavigation.org/docs/en/custom-navigators.html#navigator-navigation-prop
这可能吗? 主要的原因我想这样做,是为了能够@Inject和使用@Observer为mobx商店。 当我在店里去改变背景颜色这样,它会改变每一个具有储存注入,并观察堆栈。
编辑
当我从打电话MessagesStack:
export default createBottomTabNavigator({
DayStack: {
screen: DayStack,
navigationOptions: {...}
}
MessagesStack: {
screen: MessagesStack,
navigationOptions: {...}
}
... OtherStacks here...
}, {
initialRouteName: 'DayStack',
});