无法在反应导航中将道具从Stacknavigator传递到DrawerNavigator

时间:2018-07-28 12:15:34

标签: javascript reactjs react-native navigation react-navigation

目前我在屏幕上有这种痕迹:

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,
    },
  }),
  }
)

并且我试图将参数从启动屏幕传递到LoggedIn屏幕,但是似乎在TabNavigator(在主屏幕中)中未定义参数

我这样传递

this.props.navigation.navigate('LoggedIn',{testData: 'testing'}) 
当我登录 this.props.navigation.state.params 时,在 componentDidMount()函数中

我不确定。可能是什么原因?

1 个答案:

答案 0 :(得分:0)

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

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