是否可以使用带有子页面的 react-navigation-drawer?
Is possible react-navigation-drawer with subpages?
我正在使用带有 react-navigation-drawer 的 react-native 来生成用于导航 beetwen 屏幕的侧边菜单。
我的问题是:是否存在将子页面放入侧边菜单的方法或指南?
欢迎任何建议,并提前感谢您
左边是我的菜单,右边是我想要的:
您可以使用
自定义它
CustomDrawerContent
它有很多选项,请阅读有关它的信息,并非所有项目都需要定制
我只是为您快速制作了这个示例
文档
https://reactnavigation.org/docs/drawer-navigator/#providing-a-custom-drawercontent
import React from 'react';
import { View, Text,TouchableOpacity } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import {
createDrawerNavigator,
DrawerContentScrollView,
DrawerItemList,
DrawerItem,
} from '@react-navigation/drawer';
import Animated from 'react-native-reanimated';
function Feed() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Feed Screen</Text>
</View>
);
}
function Article() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Article Screen</Text>
</View>
);
}
function CustomDrawerContent({ navigation ,progress, ...rest }) {
const translateX = Animated.interpolate(progress, {
inputRange: [0, 1],
outputRange: [-100, 0],
});
const [isshow,show] = React.useState(false)
return (
<DrawerContentScrollView {...rest}>
<Animated.View style={{ transform: [{ translateX }] }}>
<TouchableOpacity onPress={()=>{show(true)}}>
<Text>
press me
</Text>
</TouchableOpacity>
<View>
{isshow ? (
<View>
<TouchableOpacity onPress={()=>{navigation.navigate('Feed')}}>
<Text> page one 1</Text>
</TouchableOpacity>
<TouchableOpacity onPress={()=>{navigation.navigate('Article')}}>
<Text> page one 2</Text>
</TouchableOpacity>
</View>
):null}
</View>
</Animated.View>
</DrawerContentScrollView>
);
}
const Drawer = createDrawerNavigator();
function MyDrawer() {
return (
<Drawer.Navigator drawerContent={props => <CustomDrawerContent {...props} />}>
<Drawer.Screen name="Feed" component={Feed} />
<Drawer.Screen name="Article" component={Article} />
</Drawer.Navigator>
);
}
export default function App() {
return (
<NavigationContainer>
<MyDrawer />
</NavigationContainer>
);
}
博览会link
我正在使用带有 react-navigation-drawer 的 react-native 来生成用于导航 beetwen 屏幕的侧边菜单。
我的问题是:是否存在将子页面放入侧边菜单的方法或指南?
欢迎任何建议,并提前感谢您
左边是我的菜单,右边是我想要的:
您可以使用
自定义它CustomDrawerContent
它有很多选项,请阅读有关它的信息,并非所有项目都需要定制 我只是为您快速制作了这个示例
文档
https://reactnavigation.org/docs/drawer-navigator/#providing-a-custom-drawercontent
import React from 'react';
import { View, Text,TouchableOpacity } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import {
createDrawerNavigator,
DrawerContentScrollView,
DrawerItemList,
DrawerItem,
} from '@react-navigation/drawer';
import Animated from 'react-native-reanimated';
function Feed() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Feed Screen</Text>
</View>
);
}
function Article() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Article Screen</Text>
</View>
);
}
function CustomDrawerContent({ navigation ,progress, ...rest }) {
const translateX = Animated.interpolate(progress, {
inputRange: [0, 1],
outputRange: [-100, 0],
});
const [isshow,show] = React.useState(false)
return (
<DrawerContentScrollView {...rest}>
<Animated.View style={{ transform: [{ translateX }] }}>
<TouchableOpacity onPress={()=>{show(true)}}>
<Text>
press me
</Text>
</TouchableOpacity>
<View>
{isshow ? (
<View>
<TouchableOpacity onPress={()=>{navigation.navigate('Feed')}}>
<Text> page one 1</Text>
</TouchableOpacity>
<TouchableOpacity onPress={()=>{navigation.navigate('Article')}}>
<Text> page one 2</Text>
</TouchableOpacity>
</View>
):null}
</View>
</Animated.View>
</DrawerContentScrollView>
);
}
const Drawer = createDrawerNavigator();
function MyDrawer() {
return (
<Drawer.Navigator drawerContent={props => <CustomDrawerContent {...props} />}>
<Drawer.Screen name="Feed" component={Feed} />
<Drawer.Screen name="Article" component={Article} />
</Drawer.Navigator>
);
}
export default function App() {
return (
<NavigationContainer>
<MyDrawer />
</NavigationContainer>
);
}
博览会link