React Native Application System Design
Here's a scalable file structure for your React Native app with login and drawer navigation:
code
/src
/api # API related code
/assets # Static assets like images, fonts
/components # Reusable UI components
/config # Configuration files
/navigation # Navigation related code
/screens # Screen components
/auth # Authentication screens
/home # Home screen
/utils # Utility functions
App.js # Root component
Login Screen
jsx
// src/screens/auth/LoginScreen.js
import React, { useState } from 'react';
import { View, Text, TextInput, TouchableOpacity, StyleSheet } from 'react-native';
const LoginScreen = ({ navigation }) => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const handleLogin = () => {
// Auth logic would go here
navigation.reset({
index: 0,
routes: [{ name: 'DrawerNavigator' }],
});
};
return (
<View style={styles.container}>
<Text style={styles.title}>Welcome Back</Text>
<TextInput
style={styles.input}
placeholder="Email"
value={email}
onChangeText={setEmail}
keyboardType="email-address"
/>
<TextInput
style={styles.input}
placeholder="Password"
value={password}
onChangeText={setPassword}
secureTextEntry
/>
<TouchableOpacity style={styles.button} onPress={handleLogin}>
<Text style={styles.buttonText}>Login</Text>
</TouchableOpacity>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20,
justifyContent: 'center',
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 30,
textAlign: 'center',
},
input: {
height: 50,
borderWidth: 1,
borderColor: '#ddd',
borderRadius: 8,
marginBottom: 15,
paddingHorizontal: 15,
},
button: {
backgroundColor: '#3498db',
height: 50,
borderRadius: 8,
justifyContent: 'center',
alignItems: 'center',
},
buttonText: {
color: '#fff',
fontSize: 16,
fontWeight: 'bold',
},
});
export default LoginScreen;
Home Screen
jsx
// src/screens/home/HomeScreen.js
import React from 'react';
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
const HomeScreen = ({ navigation }) => {
return (
<View style={styles.container}>
<View style={styles.header}>
<TouchableOpacity onPress={() => navigation.openDrawer()}>
<Text style={styles.menuIcon}>☰</Text>
</TouchableOpacity>
<Text style={styles.headerTitle}>Home</Text>
<View style={{width: 24}} />
</View>
<View style={styles.content}>
<Text style={styles.welcomeText}>Welcome to the Home Screen!</Text>
<Text>This is your dashboard content.</Text>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#f5f5f5',
},
header: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
padding: 16,
backgroundColor: '#fff',
elevation: 2,
},
menuIcon: {
fontSize: 24,
},
headerTitle: {
fontSize: 18,
fontWeight: 'bold',
},
content: {
flex: 1,
padding: 20,
alignItems: 'center',
justifyContent: 'center',
},
welcomeText: {
fontSize: 20,
marginBottom: 10,
}
});
export default HomeScreen;
Navigation Setup
jsx
// src/navigation/index.js
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { createDrawerNavigator } from '@react-navigation/drawer';
import LoginScreen from '../screens/auth/LoginScreen';
import HomeScreen from '../screens/home/HomeScreen';
import ProfileScreen from '../screens/profile/ProfileScreen';
const Stack = createStackNavigator();
const Drawer = createDrawerNavigator();
const DrawerNavigator = () => {
return (
<Drawer.Navigator>
<Drawer.Screen name="Home" component={HomeScreen} />
<Drawer.Screen name="Profile" component={ProfileScreen} />
</Drawer.Navigator>
);
};
const AppNavigator = () => {
return (
<NavigationContainer>
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen name="DrawerNavigator" component={DrawerNavigator} />
</Stack.Navigator>
</NavigationContainer>
);
};
export default AppNavigator;
Main App File
jsx
// src/App.js
import React from 'react';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import AppNavigator from './navigation';
const App = () => {
return (
<SafeAreaProvider>
<AppNavigator />
</SafeAreaProvider>
);
};
export default App;
Required Dependencies
code
npm install @react-navigation/native @react-navigation/stack @react-navigation/drawer
npm install react-native-gesture-handler react-native-reanimated react-native-screens react-native-safe-area-context
Would you like me to explain or break down the code?