|
| 1 | +import { NavigationContainer, useNavigation } from '@react-navigation/native'; |
| 2 | +import React, { useState } from 'react'; |
| 3 | +import { Button, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; |
| 4 | + |
| 5 | +import { createNativeStackNavigator } from '@react-navigation/native-stack'; |
| 6 | + |
| 7 | +function ProfileScreen() { |
| 8 | + const navigation = useNavigation(); |
| 9 | + const [count, setCount] = useState(0); |
| 10 | + const onPress = () => setCount(prevCount => prevCount + 1); |
| 11 | + |
| 12 | + return ( |
| 13 | + <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> |
| 14 | + <Text>Profile Screen</Text> |
| 15 | + <Button title="goto Home" onPress={() => navigation.navigate('Home')} /> |
| 16 | + <View style={styles.countContainer}> |
| 17 | + <Text>Count: {count}</Text> |
| 18 | + </View> |
| 19 | + <TouchableOpacity style={styles.button} onPress={onPress}> |
| 20 | + <Text>Press Here</Text> |
| 21 | + </TouchableOpacity> |
| 22 | + </View> |
| 23 | + ); |
| 24 | +} |
| 25 | + |
| 26 | +function HomeScreen() { |
| 27 | + const [count, setCount] = useState(0); |
| 28 | + const onPress = () => setCount(prevCount => prevCount + 1); |
| 29 | + |
| 30 | + return ( |
| 31 | + <View style={styles.container}> |
| 32 | + <View style={styles.countContainer}> |
| 33 | + <Text>Count: {count}</Text> |
| 34 | + </View> |
| 35 | + <TouchableOpacity style={styles.button} onPress={onPress}> |
| 36 | + <Text>Press Here</Text> |
| 37 | + </TouchableOpacity> |
| 38 | + </View> |
| 39 | + ); |
| 40 | +} |
| 41 | + |
| 42 | +const styles = StyleSheet.create({ |
| 43 | + container: { |
| 44 | + flex: 1, |
| 45 | + justifyContent: 'center', |
| 46 | + paddingHorizontal: 10, |
| 47 | + }, |
| 48 | + button: { |
| 49 | + alignItems: 'center', |
| 50 | + backgroundColor: '#DDDDDD', |
| 51 | + padding: 10, |
| 52 | + }, |
| 53 | + countContainer: { |
| 54 | + alignItems: 'center', |
| 55 | + padding: 10, |
| 56 | + }, |
| 57 | +}); |
| 58 | + |
| 59 | +const Stack = createNativeStackNavigator(); |
| 60 | + |
| 61 | +function RootStack() { |
| 62 | + return ( |
| 63 | + <Stack.Navigator initialRouteName="Profile"> |
| 64 | + <Stack.Screen |
| 65 | + name="Home" |
| 66 | + component={HomeScreen} |
| 67 | + options={{ |
| 68 | + headerTransparent: true, |
| 69 | + headerShadowVisible: false, |
| 70 | + }} |
| 71 | + /> |
| 72 | + <Stack.Screen name="Profile" component={ProfileScreen} /> |
| 73 | + </Stack.Navigator> |
| 74 | + ); |
| 75 | +} |
| 76 | + |
| 77 | +export default function App() { |
| 78 | + return ( |
| 79 | + <NavigationContainer> |
| 80 | + <RootStack /> |
| 81 | + </NavigationContainer> |
| 82 | + ); |
| 83 | +} |
0 commit comments