-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApp.js
More file actions
40 lines (36 loc) · 1.38 KB
/
App.js
File metadata and controls
40 lines (36 loc) · 1.38 KB
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
import React, { useEffect, useState } from 'react';
import AppProvider from './src/context/provider/AppProvider';
import MainStackNavigator from './src/navigation/stack/MainStackNavigator';
import SplashScreen from 'react-native-splash-screen';
import LoginScreen from './src/containers/login/LoginScreen';
import { getAllGroupIncludeImages } from './src/model/GroupModel';
import { getCurrentUser } from './src/service/AuthService';
import {useErrorHandler} from 'react-error-boundary';
function App() {
const [isLoggedIn, setIsLoggedIn] = useState(false);
const handleError = useErrorHandler(); // for error handling
useEffect(() => { // initialize app data
if (getCurrentUser() == null) { // new user
setTimeout(() => {
SplashScreen.hide();
}, 2000);
} else { // logged-in user
// initialize user data
getAllGroupIncludeImages().then(() => {
setIsLoggedIn(true);
// Then hide splash screen
setTimeout(() => {
SplashScreen.hide();
}, 1000);
}).catch(err => handleError(err));
}
}, []);
return (
<>
<AppProvider>
{isLoggedIn ? <MainStackNavigator/> : <LoginScreen setIsLoggedIn={setIsLoggedIn}/>}
</AppProvider>
</>
)
}
export default App;