我在https://reactnavigation.org/docs/navigators/drawer中使用DrawerNavigator 。
const MyApp = DrawerNavigator({ Home: { screen: MyHomeScreen, }, Notifications: { screen: MyNotificationsScreen, }, });
我有多个正在使用MyNotificationsScreen具有不同道具的组件的屏幕。
MyNotificationsScreen
我该怎么做:
const MyApp = DrawerNavigator({ Home: { screen: MyHomeScreen, }, Notifications1: { screen: MyNotificationsScreen(propName=val1), }, Notifications2: { screen: MyNotificationsScreen(propName=val2), }, });
在许多情况下,我认为更好的方法是:
screen: (props) => <MyNotificationsScreen {...props} propName={val1} />
这会将您的导航道具放入props.navigation.state.params中。如果您希望它们出现在this.props中(这意味着您的组件未与react- navigation紧密耦合),请使用:
screen: (props) => <MyNotificationsScreen {...props.navigation.state.params} propName={val1} />