forked from uoftblueprint/sistema
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
215 lines (195 loc) · 6.04 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import './src/services/ignoreWarnings'; // Keep at top
import React, { useState, useEffect } from 'react';
import { View, StyleSheet } from 'react-native';
import 'react-native-gesture-handler';
import {
NavigationContainer,
useNavigationContainerRef,
} from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createStackNavigator } from '@react-navigation/stack';
import {
useSafeAreaInsets,
SafeAreaProvider,
} from 'react-native-safe-area-context';
import HomeNavigator from './src/home/HomeNavigator';
import EditorNavigator from './src/editor/EditorNavigator';
import LibraryNavigator from './src/library/LibraryNavigator';
import SettingsNavigator from './src/settings/SettingsNavigator';
import { STACK_SCREENS as SETTINGS_STACK } from './src/settings/constants';
import { STACK_SCREENS as LIBRARY_STACK } from './src/library/constants';
import { STACK_SCREENS as EDITOR_STACK } from './src/editor/constants';
import Loading from './src/home/Loading';
import Tutorial from './src/home/Tutorial';
import Welcome from './src/home/Welcome';
import { Provider } from 'react-redux';
import configureStore from './src/services/configureStore';
import LibraryNavIcon from './assets/icons/libraryNavIcon.svg';
import HomeNavIcon from './assets/icons/homeNavIcon.svg';
import LessonPlanEditorNavIcon from './assets/icons/lessonPlanEditorNavIcon.svg';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import ActivityCardService from './src/services/ActivityCardService';
import LessonPlanService from './src/services/LessonPlanService';
import { AppColors } from './src/Styles.config';
const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: 3,
staleTime: 1000 * 60 * 3, // 3 minute stale time
cacheTime: 1000 * 60 * 60 * 12, // 12 hour cache
},
},
});
const STACK_SCREENS = {
TABS: 'TabsNavigator',
HOME: 'HomeNavigator',
TUTORIAL: 'Tutorial',
WELCOME: 'Welcome',
EDITOR: EDITOR_STACK.NAVIGATOR,
LIBRARY: LIBRARY_STACK.NAVIGATOR,
SETTINGS: SETTINGS_STACK.NAVIGATOR
};
const tabIcon = (iconSVG, isFocused) => {
const tabColor = isFocused ? AppColors.tertiary : '#000000';
const icon = React.createElement(iconSVG, {
width: 32,
height: 32,
marginBottom: 5,
color: tabColor,
});
return (
<View style={styles.container}>
{icon}
{
<View
style={[
styles.underline,
{ backgroundColor: isFocused ? tabColor : '#B8CFE4' },
]}
/>
}
</View>
);
};
const Tab = createBottomTabNavigator();
const TabsNavigator = () => {
const insets = useSafeAreaInsets();
return (
<Tab.Navigator
initialRouteName={STACK_SCREENS.HOME}
screenOptions={{
tabBarActiveBackgroundColor: '#B8CFE4',
tabBarInactiveBackgroundColor: '#B8CFE4',
tabBarStyle: {
height: 60 + insets.bottom,
backgroundColor: '#B8CFE4',
},
headerShown: false,
}}>
<Tab.Screen
name={STACK_SCREENS.HOME}
component={HomeNavigator}
options={{
tabBarShowLabel: false,
headerShown: false,
tabBarIcon: ({ focused }) => tabIcon(HomeNavIcon, focused),
}}
/>
<Tab.Screen
name={STACK_SCREENS.EDITOR}
component={EditorNavigator}
options={{
tabBarShowLabel: false,
tabBarIcon: ({ focused }) => tabIcon(LessonPlanEditorNavIcon, focused),
tabBarStyle: { display: 'none' },
}}
/>
<Tab.Screen
name={STACK_SCREENS.LIBRARY}
component={LibraryNavigator}
options={{
tabBarShowLabel: false,
tabBarIcon: ({ focused }) => tabIcon(LibraryNavIcon, focused),
}}
/>
<Tab.Screen
name={STACK_SCREENS.SETTINGS}
component={SettingsNavigator}
options={{
tabBarShowLabel: false,
tabBarButton: () => null, // Not displayed in bottom tab bar
tabBarVisible: false,
}}
/>
</Tab.Navigator>
)
}
const Stack = createStackNavigator();
const MainNavigator = ({displayTutorial}) => {
const navigationRef = useNavigationContainerRef();
return (
<NavigationContainer ref={navigationRef} independent={true}>
<Stack.Navigator
initialRouteName={displayTutorial ? STACK_SCREENS.WELCOME : STACK_SCREENS.TABS}
screenOptions={{ headerShown: false }}
>
<Stack.Screen
name={STACK_SCREENS.WELCOME}
component={Welcome}
/>
<Stack.Screen
name={STACK_SCREENS.TUTORIAL}
component={Tutorial}
/>
<Stack.Screen
name={STACK_SCREENS.TABS}
component={TabsNavigator}
/>
</Stack.Navigator>
</NavigationContainer>
);
};
const styles = StyleSheet.create({
underline: {
width: 50,
height: 2,
},
container: {
flexDirection: 'column',
justifyContent: 'space-between',
alignItems: 'center',
},
});
const App = () => {
// State variables for displaying onboarding screens
const [shouldDisplayTutorial, setShouldDisplayTutorial] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const welcomeSetup = async () => {
LessonPlanService.isUserOnboarded().then((res) => {
setShouldDisplayTutorial(!res);
}).then(() => {
queryClient.prefetchQuery({
queryKey: ['activityCards'],
queryFn: ActivityCardService.getAllActivityCards,
});
}).finally(() => {
setIsLoading(false);
});
}
useEffect(() => {
welcomeSetup();
}, []);
return (
<SafeAreaProvider>
<QueryClientProvider client={queryClient}>
<Provider store={configureStore}>
{isLoading
? <Loading />
: <MainNavigator displayTutorial={shouldDisplayTutorial} />
}
</Provider>
</QueryClientProvider>
</SafeAreaProvider>
);
};
export default App;