我有以下stack navigator
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Settings" component={SettingsScreen} />
<Stack.Screen name="AboutUs" component={AboutUsScreen} />
<Stack.Screen name="ContactUs" component={ContactUsScreen} />
<Stack.Screen name="Blog" component={BlogScreen} />
</Stack.Navigator>
我想拥有drawer
(具有自定义抽屉内容)而不使用nesting drawer navigators
。
答案 0 :(得分:2)
我看到了您的问题,并正在努力为您提供帮助。我已经为抽屉组件定制了设计。 -首先,您可以为抽屉设计创建一个额外的文件,例如DrawerComponent.js
,并在创建抽屉导航器的代码中导入
import DrawerComponent from "./DrawerComponent";
const Primary_Nav = createDrawerNavigator(
{
screen1: {
screen: screen1,
navigationOptions: {
drawerLabel: () => null
}
},
screen2: {
screen: screen2,
navigationOptions: {
drawerLabel: "detail"
}
},
{
initialRouteName: "screen1",
drawerPosition: "left",
drawerType: "slide",
contentComponent: DrawerComponent //<<< i added this
}
);
const PrimaryNav = createAppContainer(Primary_Nav);
export default PrimaryNav;
现在在DrawerComponent.js
中,您可以根据需要创建自定义组件的内容。
import React, { Component } from "react";
import { Text, View, TouchableOpacity } from "react-
native";
export default class DrawerComponent extends Component {
constructor(props) {
super(props);
this.state = {
};
}
render() {
const { navigation } = this.props;
return (
<View style={{ flex: 1, paddingVertical: 40,paddingHorizontal: 20 }}>
<TouchableOpacity
style={{ margin: 20 }}
onPress={() => navigation.navigate("screen1")}
>
<Text>Home</Text>
</TouchableOpacity>
<TouchableOpacity
style={{ margin: 20 }}
onPress={() => navigation.navigate("screen2")}
>
<Text>Detail</Text>
</TouchableOpacity>
</View>
);
}
}
我希望它会对您有所帮助。谢谢,祝您编程愉快。