简体   繁体   English

我需要在 React Native 中为 Drawertoggling 添加一个图标

[英]I need to add an Icon for Drawertoggling in React Native

I got the following error while trying to do so.I am using React Navigation 5 It is showing Object is not a function尝试这样做时出现以下错误。我正在使用 React Navigation 5它显示 Object 不是 function

Here is my code这是我的代码

 const HeaderLeft = ({ navigation }) => { return ( <View style={{flexDirection: 'row'}}> <Icon name="menu" size={24} color= 'white' onPress={ () => navigation.toggleDrawer() } /> </View> );}

This is how I added it in screen这就是我在屏幕中添加它的方式

 <MenuNavigator.Navigator initialRouteName='Menu' screenOptions={{ headerStyle: { backgroundColor: "#512DA8" }, headerTintColor: "#fff", headerLeft: ({ navigation }) => (<HeaderLeft navigation={navigation} />), headerTitleStyle: { color: "#fff" }, }} >

Please Help me on the above Bug请帮助我解决上述错误

You are getting the navigation from the wrong place.您从错误的地方获得导航。 It should be它应该是

 screenOptions = {
      (navigation) => ({
          headerStyle: {
            backgroundColor: "#512DA8"
          },
          headerTintColor: "#fff",
          headerLeft: () => ( < HeaderLeft navigation = {
                navigation
              }
              />),
              headerTitleStyle: {
                color: "#fff"
              }})}

The navigation you are passing in would probably would be null您传入的导航可能是 null

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

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