mirror of
https://github.com/zhigang1992/examples.git
synced 2026-01-12 22:47:03 +08:00
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
import React from 'react';
|
|
import { Button, View } from 'react-native';
|
|
import { createDrawerNavigator } from '@react-navigation/drawer';
|
|
import { NavigationContainer } from '@react-navigation/native';
|
|
|
|
function HomeScreen({ navigation }) {
|
|
return (
|
|
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
|
|
<Button
|
|
onPress={navigation.openDrawer}
|
|
title="Open navigation drawer"
|
|
/>
|
|
<Button
|
|
onPress={() => navigation.navigate('Notifications')}
|
|
title="Go to notifications"
|
|
/>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
function NotificationsScreen({ navigation }) {
|
|
return (
|
|
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
|
|
<Button
|
|
onPress={navigation.openDrawer}
|
|
title="Open navigation drawer"
|
|
/>
|
|
<Button
|
|
onPress={() => navigation.goBack()}
|
|
title="Go back home"
|
|
/>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const Drawer = createDrawerNavigator();
|
|
|
|
export default function App() {
|
|
return (
|
|
<NavigationContainer>
|
|
<Drawer.Navigator initialRouteName="Home">
|
|
<Drawer.Screen name="Home" component={HomeScreen} />
|
|
<Drawer.Screen name="Notifications" component={NotificationsScreen} />
|
|
</Drawer.Navigator>
|
|
</NavigationContainer>
|
|
);
|
|
} |