简体   繁体   English

具有React Native的Android独立菜单按钮

[英]Android standalone menu button with React native

I need to make a standalone (without additional bars or else) menu button in my React Native (v 0.47.2) Android app: 我需要在我的React Native(v 0.47.2)Android应用程序中制作一个独立的菜单按钮(没有其他栏)。

菜单已关闭

On touch it has to open side menu: 触摸时必须打开侧面菜单:

菜单已打开

Which component I need to use? 我需要使用哪个组件?

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 . 您可以将StackNavigatorHeader的颜色设置为应用程序的backgroundColortransparent 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,你会需要堆你StackNavigatorDrawerNavigatoronPress={() => 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.

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