答案 0 :(得分:2)
您正在使用react-navigation
。使用StackNavigator
。 StackNavigator
可以设置Headers
。在Header
中,您可以prop
传递Icon
(或任何Component
)。
这是一个例子:
// all your other imports
import Icon from "react-native-vector-icons/Ionicons";
import {
Platform,
} from "react-native";
const MenuButton = ({ navigate }) => {
return (
<Icon
name={Platform.OS === "ios" ? "ios-menu-outline" : "md-menu"}
onPress={() => navigate("DrawerOpen")}
/>
)
}
StackNavigator({
Notifications: {
screen: Example,
navigationOptions: ({ navigation }) => ({
headerLeft: <MenuButton {...navigation} />,
}),
},
headerLeft
(或headerRight
)可用于您的情况Documentation)。我在这里传递<MenuButton />
组件。您可以设置{{1}的颜色将StackNavigator
添加到您应用的Header
,或backgroundColor
。这样,就不会有任何可见的内容,只有菜单按钮。
你需要在transparent
中将StackNavigator
与DrawerNavigator
叠加起来才能使onPress={() => navigate("DrawerOpen")}
工作。
在DrawerNavigator
中,您可以使用传递自定义组件的contentComponent
,其中包含您的菜单。
这是一个更复杂的设置http://rationalappdev.com/cross-platform-navigation-in-react-native/