This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
57 lines (50 loc) · 1.43 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, {useState, useEffect} from 'react';
import {SafeAreaView} from 'react-native';
import {Provider} from 'react-redux';
import {PersistGate} from 'redux-persist/integration/react';
import {store, persistor} from './src/store';
import Navigation from './src/Navigation';
import Loading from './src/screens/Loading';
import Welcome from './src/screens/Welcome';
import {saveCredentials, loadCredentials} from './src/utils';
const App = () => {
useEffect(() => {
async function anyNameFunction() {
let result = await loadCredentials();
if (result !== null) {
setFirstTimeUser(false);
}
setIsReady(true);
}
anyNameFunction();
}, []);
const [firstTimeUser, setFirstTimeUser] = useState(true);
const [isReady, setIsReady] = useState(false);
const saveUserData = async (username) => {
await saveCredentials(username, username);
setFirstTimeUser(false);
};
if (isReady === false) {
return <Loading />;
}
if (firstTimeUser === true && isReady === true) {
return <Welcome saveUserData={saveUserData} />;
}
return (
<SafeAreaView style={{flex: 1}}>
<Provider store={store}>
<PersistGate loading={<Loading />} persistor={persistor}>
<Navigation />
</PersistGate>
</Provider>
</SafeAreaView>
);
};
export default App;