简体   繁体   中英

Can not pass prop from Stacknavigator to DrawerNavigator in react-navigation

Currently I have this scema for screens:

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

and I am trying to pass params from Splash screen to LoggedIn screen but it seems that params are undefined in TabNavigator(In Home Screen)

I am passing it like this

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

in componentDidMount() function when I log this.props.navigation.state.params I get undefined. What might be the reason?

Did you try this, ( from this discussion on github )

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM