first of all install nodejs form nodejs.org
open your command prompt and type :-
npx @react-native-community/cli init MyFirstApp:-
open project folder and open your App.tsx file :-
App.tsx file code :-
import 'react-native-gesture-handler';
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import HomeScreen from './screens/HomeScreen';
import DetailsScreen from './screens/DetailsScreen';
import ProfileScreen from './screens/ProfileScreen';
import SettingsScreen from './screens/SettingsScreen';
const Stack = createNativeStackNavigator();
const App = () => {
return (
);
};
export default App;
MyFirstApp/screens/HomeScreen.tsx file code:-
import React from 'react';
import {
View,
Text,
TouchableOpacity,
StyleSheet,
StatusBar,
ScrollView,
} from 'react-native';
const HomeScreen = ({ navigation }: any) => {
return (
Welcome to My App
navigation.navigate('Details', { message: 'Hello from Home!' })}
>
Go to Details
navigation.navigate('Profile')}
>
Go to Profile
navigation.navigate('Settings')}
>
Go to Settings
);
};
export default HomeScreen;
const styles = StyleSheet.create({
container: {
flexGrow: 1,
backgroundColor: '#121212',
padding: 24,
alignItems: 'center',
justifyContent: 'center',
},
header: {
fontSize: 28,
color: '#fff',
marginBottom: 32,
fontWeight: 'bold',
},
button: {
backgroundColor: '#4a90e2',
paddingVertical: 14,
paddingHorizontal: 28,
borderRadius: 12,
marginVertical: 12,
width: '100%',
alignItems: 'center',
elevation: 4, // Android shadow
shadowColor: '#000', // iOS shadow
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.3,
shadowRadius: 4,
},
buttonText: {
color: '#fff',
fontSize: 18,
fontWeight: '600',
},
});
MyFirstApp/screens/DetailsScreen.tsx file code:-
import React from 'react';
import { View, Text, Button, StyleSheet } from 'react-native';
const DetailsScreen = ({ route, navigation }: any) => {
const { message } = route.params || {};
return (
Details Screen
{message}
);
};
export default DetailsScreen;
const styles = StyleSheet.create({
container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
title: { fontSize: 24, marginBottom: 20 },
});
MyFirstApp/screens/ProfileScreen.tsx file code:-
import React from 'react';
import { View, Text, Button, StyleSheet } from 'react-native';
const ProfileScreen = ({ navigation }: any) => {
return (
Profile Screen
);
};
export default ProfileScreen;
const styles = StyleSheet.create({
container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
title: { fontSize: 24, marginBottom: 20 },
});
MyFirstApp/screens/
SettingsScreen.tsx file code:-
import React from 'react';
import { View, Text, Button, StyleSheet } from 'react-native';
const SettingsScreen = ({ navigation }: any) => {
return (
Settings Screen
);
};
export default SettingsScreen;
const styles = StyleSheet.create({
container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
title: { fontSize: 24, marginBottom: 20 },
});
finally run it:-
npx react-native run-android