[英]Android standalone menu button with React native
You are using react-navigation
. 您正在使用
react-navigation
。 Use the StackNavigator
. 使用
StackNavigator
。 The StackNavigator
can set Headers
. StackNavigator
可以设置Headers
。 In the Header
, there is a prop
to which you can pass an Icon
(or any Component
). 在
Header
,有一个可以传递Icon
(或任何Component
)的prop
。 Here an example: 这里是一个例子:
// 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} />,
}),
},
The headerLeft
(or headerRight
) can be used for you case ( Documentation) . headerLeft
(或headerRight
)可用于您的案例( 文档) 。 Here I pass <MenuButton />
component. 在这里,我传递了
<MenuButton />
组件。 You can set the color of the StackNavigator
s Header
to the backgroundColor
of your app, or transparent
. 您可以将
StackNavigator
的Header
的颜色设置为应用程序的backgroundColor
或transparent
。 That way, there won`t be anything visible, but the menu button. 这样,除了菜单按钮之外,什么都看不到。
Of yourse you would need to stack you StackNavigator
in a DrawerNavigator
for the onPress={() => navigate("DrawerOpen")}
to work. yourse,你会需要堆你
StackNavigator
在DrawerNavigator
为onPress={() => navigate("DrawerOpen")}
工作。 In the DrawerNavigator
you can use a contentComponent
which you pass your custom component, that contains your menu. 在
DrawerNavigator
,可以使用contentComponent
,它传递包含菜单的自定义组件。
Here is a more complex setup http://rationalappdev.com/cross-platform-navigation-in-react-native/ 这是一个更复杂的设置http://rationalappdev.com/cross-platform-navigation-in-react-native/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.