在React Navigation 5中单击标题图标时打开抽屉

时间:2020-03-24 17:04:51

标签: react-native navigation version native

当我点击图标时,我正在为React Navigation 5打开一个抽屉而苦苦挣扎,出现此错误SumOfNumbers.java

问题出在undefined is not an object (evaluating 'navigation.openDrawer')上,图标显示正确,但是当我单击它时出现上面的错误。即使我从道具中获得headerRight,我也不明白为什么我不能使用它来调用navigation

我还测试了openDrawer(),它显示了相同的错误。

我想念什么?

navigation.toggleDrawer()

1 个答案:

答案 0 :(得分:1)

也许尝试:

const defaultOptions = ({ navigation }) => ({
    headerLeft: () => (
        headerStyle: {
      backgroundColor: Colors.primary
    },
    headerTitleStyle: {
      fontFamily: "raleway-bold"
    },
    headerBackTitleStyle: {
      fontFamily: "raleway-regular"
    },
    headerTintColor: "white",
    headerRight: () => (
      <TouchableOpacity onPress={() => navigation.openDrawer()}>
        <Ionicons
          name={Platform.OS === "android" ? "md-menu" : "ios-menu"}
          size={32}
          color="white"
          style={styles.menu}
        />
      </TouchableOpacity>
    )
});