/
Main.tsx
104 lines (94 loc) · 2.63 KB
/
Main.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import React from 'react'
import { NavigationContainer } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'
import {
useFonts as usePoppins,
Poppins_700Bold,
} from '@expo-google-fonts/poppins'
import {
useFonts as useDidactGothic,
DidactGothic_400Regular,
} from '@expo-google-fonts/didact-gothic'
import AppLoading from 'expo-app-loading'
import theme from './lib/defaultTheme'
import routes from './lib/routeDefinitions'
import { useAuthentication } from './context/authentication'
import { useSecrets } from './context/secrets'
import Home from './screens/Home'
import TypeNewSecretScreen from './screens/TypeNewSecretScreen'
import ScanNewSecretScreen from './screens/ScanNewSecretScreen'
import Auth from './components/Auth'
import HomeHeaderRight from './components/HomeHeaderRight'
import DefaultHeaderLeft from './components/DefaultHeaderLeft'
const Stack = createStackNavigator()
const UI_STRINGS = {
routes: {
home: {
title: 'Your Tokens',
},
scan: {
title: 'Scan QR Code',
},
type: {
title: 'New Secret',
},
},
}
export default function Main() {
const [hasPoppinsLoaded] = usePoppins({
Poppins_700Bold,
})
const [hasDidactLoaded] = useDidactGothic({
DidactGothic_400Regular,
})
const { isInitialized } = useSecrets()
const { user, loading, handleLogin } = useAuthentication()
if (!hasDidactLoaded || !hasPoppinsLoaded || !isInitialized || loading) {
return <AppLoading />
}
if (!user) {
return <Auth {...{ handleLogin }} />
}
return (
<NavigationContainer>
<Stack.Navigator
{...{
initialRouteName: routes.home.name,
screenOptions: {
headerStyle: {
backgroundColor: theme.colors.primary,
},
headerTitleStyle: {
color: theme.colors.surface,
},
},
}}
>
<Stack.Screen
name={routes.home.name}
component={Home}
options={{
title: UI_STRINGS.routes.home.title,
headerRight: HomeHeaderRight,
}}
/>
<Stack.Screen
name={routes.scan.name}
component={ScanNewSecretScreen}
options={{
title: UI_STRINGS.routes.scan.title,
headerLeft: DefaultHeaderLeft,
}}
/>
<Stack.Screen
name={routes.type.name}
component={TypeNewSecretScreen}
options={{
title: UI_STRINGS.routes.type.title,
headerLeft: DefaultHeaderLeft,
}}
/>
</Stack.Navigator>
</NavigationContainer>
)
}