简体   繁体   English

react-navigation如何从customDrawer导航导航

[英]react-navigation how to navigate from customDrawer navigation

I am using createDrawerNavigator and inside this I made a custom profile view. 我正在使用createDrawerNavigator ,在其中我创建了一个自定义的配置文件视图。 When I press navigate I want to move to another screen. 当我按navigate我想移动到另一个屏幕。

But this give me an error undefined is not an object (evaluating"_this.props.navigation") . 但这给了我一个错误undefined is not an object (evaluating"_this.props.navigation") Other components one , two , three works fine. 其他组件onetwothree工作正常。

This is my code: 这是我的代码:

export default class App extends Component {
  render() {

    return (
      <View style={{flex:1, marginTop:30}}>
        <AppContainer/>
      </View>
    );
  }
}

    const CustomDrawerContentComponent = (props)=> {
      return(
      <SafeAreaView style={{flex:1}}>
        <View style={{ height:100, backgroundColor: '#9FA8DA' }}>
          <Image
                style={{marginLeft:20,height:100,width:100,borderRadius:50}}
                source={require('./assets/puppy.jpg')}/>
        </View>

        <View style={{flexDirection:'row', margin:20, alignItems:'center'}}>
    //////here is where I get an error
        <TouchableOpacity
            style={{marginTop:0}}
            onPress={()=> {this.props.navigation.navigate('profile')}}>
          <Text style={{fontSize:18, fontWeight:'bold'}}>navigate</Text>
          <Image
                style={{height:12,width:12}}
                source={require('./assets/drawable-hdpi/ic_arrow_depth.png')}/>
        </TouchableOpacity>
        </View>
        <ScrollView>
          <DrawerItems {...props}/>
        </ScrollView>
      </SafeAreaView>
      )
    }

const AppDrawerNavigator = createDrawerNavigator({
    one: AppStackNavigator,
    two: BoardScreen,
    three: NotificationScreen,
  },{
    contentComponent:CustomDrawerContentComponent,
  })

const AppStackNavigator = createStackNavigator({
  profile: {
  screen: profileScreen,
  navigationOptions: {
      header: null
    },
  },
})

const StartSwitchNavigator = createSwitchNavigator(
    {
      App: AppDrawerNavigator,
    },
    {
      initialRouteName: 'App',
    }
  )

在此输入图像描述

Your CustomDrawerContentComponent component is functional component. 您的CustomDrawerContentComponent组件是功能组件。 Use props.navigation directly instead of this.props 直接使用props.navigation而不是this.props

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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