-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
64 lines (58 loc) · 1.84 KB
/
App.tsx
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import React from 'react';
import {SafeAreaView} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import {HomeScreen} from './src/screens/HomeScreen/index';
import {GPSScreen} from './src/screens/GPSScreen/index';
import {Provider} from './src/context/store';
import auth from '@react-native-firebase/auth';
const Stack = createStackNavigator<NavigationT.RootStackT>();
const App: React.FC = () => {
// Set an initializing state whilst Firebase connects
const [initializing, setInitializing] = React.useState<boolean>(true);
const [user, setUser] = React.useState<FirebaseT.UserT>();
// Handle user state changes
const onAuthStateChanged = (currentUser: FirebaseT.UserT) => {
setUser(currentUser);
if (initializing) {
setInitializing(false);
}
};
React.useEffect(() => {
const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
return subscriber; // unsubscribe on unmount
});
return (
<Provider>
<SafeAreaView style={{flex: 1}}>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerShown: false,
}}>
{user ? ( // Follow best practice: https://reactnavigation.org/docs/auth-flow
<>
<Stack.Screen
name="GPS"
options={{gestureEnabled: false}}
component={GPSScreen}
/>
</>
) : (
<>
<Stack.Screen name="LogIn" component={HomeScreen} />
</>
)}
</Stack.Navigator>
</NavigationContainer>
</SafeAreaView>
</Provider>
);
};
export default App;