如何在选项卡屏幕中访问传递给TabNavigator的道具?

时间:2018-05-15 16:49:12

标签: react-native

我有像这样的tabnavigator

var TabNavigation = createBottomTabNavigator({
    NearbyScreen: { 
        screen: Nearby
    },
    FindScreen:{
        screen: LandmarkNavigation
    },
    NotificationScreen:{
        screen: Notifications
    },
    MyProfile:{
        screen: MyProfile
    }
})

在组件中呈现

render() {
        //console.log(this.props);
        var nearbyLocations = this.props.locationsNearby;
        return(
            <TabNavigation thisThing="thisThingValue" />
        )
    }

如何访问我在其中一个标签页面中传递的道具的价值?

2 个答案:

答案 0 :(得分:1)

我用screenProps解决了它:

return(
            <TabNavigation screenProps={thing} />
        )

通过this.props.screenProps

可以在导航器标签视图中访问它

答案 1 :(得分:0)

尝试通过此处访问this.props.navigation.state.params.thisThing