gpt4 book ai didi

javascript - 无法在 react 导航中将 Prop 从 Stacknavigator 传递到 DrawerNavigator

转载 作者:行者123 更新时间:2023-12-03 01:25:27 26 4
gpt4 key购买 nike

目前我有这个屏幕场景:

const Tabs = TabNavigator({
Home: {
screen: Home,
navigationOptions: {
tabBarLabel: 'Home',
tabBarIcon: <Image style={{height: 22, width: 22}} source={require('../assets/images/nav-home.png')}/>,
header: null
}
},
Thanks: {
screen: Thanks,
navigationOptions: {
tabBarLabel: 'Thanks',
tabBarIcon: <Image style={{height: 22, width: 21}} source={require('../assets/images/nav-thanks.png')}/>,
header: null
}
},
Profile: {
screen: Profile,
navigationOptions: {
gesturesEnabled: false
}
},
},
{
initialRouteName: 'Home',
tabBarPosition: 'bottom',

},
)

const Drawer = DrawerNavigator(
{
Tabs: {
screen: Tabs,
navigationOptions: {
drawerLabel: () => null
}
},
Search: {screen: SearchAndProfile}
},
{
drawerPosition: 'right',
initialRouteName: 'Tabs',
drawerOpenRoute: 'DrawerOpen',
drawerCloseRoute: 'DrawerClose',
drawerToggleRoute: 'DrawerToggle'
})

const NotLoggedIn = StackNavigator(
{
LoginScreen: {
screen: Login,
navigationOptions: {
gesturesEnabled: false,
}
},
Drawer: {screen: Drawer}
},
{
initialRouteName: 'LoginScreen',
headerMode: 'none',
navigationOptions: {
gesturesEnabled: false,
}
}
)

const LoggedIn = StackNavigator(
{
Drawer: {screen: Drawer}
},
{
headerMode: 'none',
navigationOptions: {
gesturesEnabled: false,
},
transitionConfig : () => ({
transitionSpec: {
duration: 0,
timing: Animated.timing,
easing: Easing.step0,
},
}),
}
)

export const Root = StackNavigator(
{
Splash:{screen: Splash},
LoggedIn: {
screen: LoggedIn,
navigationOptions: {
gesturesEnabled: false
}
},
NotLoggedIn: {screen: NotLoggedIn}
},
{
headerMode: 'none',
navigationOptions: {
gesturesEnabled: false,
},
transitionConfig : () => ({
transitionSpec: {
duration: 0,
timing: Animated.timing,
easing: Easing.step0,
},
}),
}
)

我正在尝试将参数从启动屏幕传递到登录屏幕,但似乎参数在 TabNavigator(在主屏幕中)中未定义

我是这样传递的

this.props.navigation.navigate('LoggedIn',{testData: 'testing'}) 

componentDidMount() 函数中,当我登录 this.props.navigation.state.params 时,我得到了未定义。可能是什么原因?

最佳答案

你尝试过这个吗?(来自此discussion on github)

this.props.navigation.navigate('LoggedIn', {}, {
type: "Navigate",
routeName: "Drawer",
params: {testData: 'testing'},
})

关于javascript - 无法在 react 导航中将 Prop 从 Stacknavigator 传递到 DrawerNavigator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51571285/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com