-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAppContent.js
57 lines (49 loc) · 1.43 KB
/
AppContent.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
import React, { useContext, useState } from 'react'
import { ActivityIndicator } from 'react-native-paper'
import { View, StyleSheet } from 'react-native'
import LoginContainer from './src/containers/LoginContainer/LoginContainer'
import CTNavigationContainer from './src/containers/CTNavigationContainer/CTNavigationContainer'
import { Context } from './src/store/Store'
/**
* The main code for the application. All items in here should have access to the store.
*/
export default function AppContent() {
const [isUserAuthenticated, setIsUserAuthenticated] = useState(false)
const state = useContext(Context)[0]
const onAuthLevelChange = (isAuthenticated) => {
setIsUserAuthenticated(isAuthenticated)
}
const renderApplication = () => {
if (isUserAuthenticated) return <CTNavigationContainer />
return <LoginContainer onAuthLevelChange={onAuthLevelChange} />
}
const renderLoadingIndicator = () => {
if (!state.isLoading) return null
return (
<View style={style.loading}>
<ActivityIndicator size="large" />
</View>
)
}
return (
<View style={style.container}>
{renderApplication()}
{renderLoadingIndicator()}
</View>
)
}
const style = StyleSheet.create({
container: {
width: '100%',
height: '100%',
},
loading: {
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
alignItems: 'center',
justifyContent: 'center',
},
})