import React from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { Ionicons } from '@expo/vector-icons';
function HomeScreen({ navigation }) {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text style={{ fontSize: 24 }}>Home Screen</Text>
</View>
);
}
function ProfileScreen({ navigation }) {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text style={{ fontSize: 24 }}>Profile Screen</Text>
</View>
);
}
const Drawer = createDrawerNavigator();
export default function App() {
return (
<NavigationContainer>
<Drawer.Navigator
screenOptions={({ navigation }) => ({
headerLeft: () => (
<TouchableOpacity onPress={() => navigation.toggleDrawer()} style={{ marginLeft: 15 }} accessibilityLabel="Open menu drawer">
<Ionicons name="menu" size={28} />
</TouchableOpacity>
),
headerTitleAlign: 'center'
})}
>
<Drawer.Screen name="Home" component={HomeScreen} />
<Drawer.Screen name="Profile" component={ProfileScreen} />
</Drawer.Navigator>
</NavigationContainer>
);
}This solution uses React Navigation's Drawer Navigator to create a side menu.
We define two simple screens: Home and Profile, each showing a centered title.
The drawer navigator wraps these screens and provides a sliding menu from the left.
We add a menu icon button in the header that toggles the drawer when tapped.
This setup follows React Native best practices and accessibility by labeling the menu button.