[英]Android standalone menu button with React native
您正在使用react-navigation
。 使用StackNavigator
。 StackNavigator
可以設置Headers
。 在Header
,有一個可以傳遞Icon
(或任何Component
)的prop
。 這里是一個例子:
// 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
)可用於您的案例( 文檔) 。 在這里,我傳遞了<MenuButton />
組件。 您可以將StackNavigator
的Header
的顏色設置為應用程序的backgroundColor
或transparent
。 這樣,除了菜單按鈕之外,什么都看不到。
yourse,你會需要堆你StackNavigator
在DrawerNavigator
為onPress={() => navigate("DrawerOpen")}
工作。 在DrawerNavigator
,可以使用contentComponent
,它傳遞包含菜單的自定義組件。
這是一個更復雜的設置http://rationalappdev.com/cross-platform-navigation-in-react-native/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.