-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
86 lines (77 loc) · 2.03 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React, { useEffect } from 'react';
import { Text, SafeAreaView, StyleSheet, Button } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
const Stack = createNativeStackNavigator();
const FirstScreen = ({navigation}) => {
function goToSecond() {
navigation.navigate('second');
}
return (
<SafeAreaView style={styles.container}>
<Text style={styles.paragraph}>
This is the first screen.
</Text>
<Button style={styles.btn} onPress={goToSecond} title="Go to Second Screen"/>
</SafeAreaView>
);
};
const SecondScreen = ({navigation}) => {
useEffect(() => {
// Add a focus listener.
const unsubscribe = navigation.addListener('focus', () => {
console.log(`[SecondScreen->useEffect->focus] focus listener fired.`);
});
return unsubscribe;
}, [navigation]);
useEffect(() => {
// Add a blur listener.
const unsubscribe = navigation.addListener('blur', () => {
console.log(`[SecondScreen->useEffect->blur] blur listener fired.`);
});
return unsubscribe;
}, [navigation]);
return (
<SafeAreaView style={styles.container}>
<Text style={styles.paragraph}>
This is the second screen.
</Text>
</SafeAreaView>
);
};
function MyNav() {
// Show the navigation for an unauthenticated user.
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="first" component={FirstScreen}/>
<Stack.Screen name="second" component={SecondScreen}/>
</Stack.Navigator>
</NavigationContainer>
);
}
export default function App() {
return (
<SafeAreaView style={styles.container}>
<MyNav/>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#ecf0f1',
padding: 8,
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
btn: {
maxWidth: 200,
color: '#FFF'
}
});