在react-navigation TabNavigator中,如何setParams

时间:2017-05-03 02:56:25

标签: react-native react-navigation

const AppTabs = TabNavigator({
Home: {
  screen: FilmList,
},
FilmCinemaList: {
  screen: FilmCinemaList,
  path: 'cart',
},
FilmGoodsList: {
    screen: FilmGoodsList,
},
FilmMe: {
    screen: FilmMe,
},
})
当我点击FilmCinemaList时,我想传递一个参数。如何使用setParams?

2 个答案:

答案 0 :(得分:2)

在呈现AppTabs时,您可以通过这种方式传递参数:

<AppTabs screenProps={{ FilmCinemaList: { ...yourParams } }}/>

您可以通过以下方式在FilmCinemaList上访问它们:

this.props.screenProps.FilmCinemaList

答案 1 :(得分:0)

通过navigationOptions,你需要做的是设置屏幕的navigationOptions,然后在TabNavigator中传递它,如下所示:

FilmCinemaList.navigationOptions = {
 'param1':'value1';
};
const AppTabs = TabNavigator({
Home: {
  screen: FilmList,
},
FilmCinemaList: {
  screen: FilmCinemaList,
  path: 'cart',
},
FilmGoodsList: {
    screen: FilmGoodsList,
},
FilmMe: {
    screen: FilmMe,
},
})

然后你可以访问它

FilmCinemaList.navigationOptions.param1

什么时候需要。