通过drawernavigator中的屏幕选项传递道具



我在https://reactnavigation.org/docs/navigators/drawer。

中使用drawernavigator。
const MyApp = DrawerNavigator({
    Home: {
        screen: MyHomeScreen,
    },
    Notifications: {
        screen: MyNotificationsScreen,
    },
});

我有多个使用MyNotificationsScreen组件的屏幕。

我该怎么做:

const MyApp = DrawerNavigator({
    Home: {
        screen: MyHomeScreen,
    },
    Notifications1: {
        screen: MyNotificationsScreen(propName=val1),
    },
    Notifications2: {
        screen: MyNotificationsScreen(propName=val2),
    },
});

在许多情况下,我认为更好的方法:

screen: (props) => <MyNotificationsScreen {...props} propName={val1} />

这将使您的NAV Props置于props.navigation.state.params中。如果您希望它们出现在此中。

screen: (props) => <MyNotificationsScreen {...props.navigation.state.params} propName={val1} />

您确实有两个选择:

1-您通过"导航呼叫"中的参数:

this.props.navigation.navigate('Notifications1', {propName: 'val1'})

2-另一种方式是创建通知1

class Notifications1 
{
  render ( )
  {
    return <MyNotificationsScreen propName="val1" />
  }
}

最新更新