-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
88 lines (81 loc) · 2.89 KB
/
App.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
import dayjs from "dayjs";
import { Provider as PaperProvider, Snackbar } from "react-native-paper";
import { AppTheme } from "./app-theme";
import isSameOrAfter from "dayjs/plugin/isSameOrAfter";
import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { WaterbodyGroupList } from "./src/screens/waterbody-group-list/waterbody-group-list.screen";
import { WaterbodyDetailsScreen } from "./src/screens/waterbody-details/waterbody-details.screen";
import { RootStackParamList } from "./root-stack-param-list.type";
import { WaterbodyDetailsRegulationScreen } from "./src/screens/waterbody-details/waterbody-details-regulation.screen";
import { SafeAreaProvider } from "react-native-safe-area-context";
import * as SplashScreen from "expo-splash-screen";
import { useAppInitialization } from "./src/utils/app.hooks";
import { useCallback } from "react";
import { RegulationsContext } from "./src/components/regulations.context";
dayjs.extend(isSameOrAfter);
dayjs.extend(isSameOrBefore);
const Stack = createNativeStackNavigator<RootStackParamList>();
// Keep the splash screen visible while we determine up to date regulations.
SplashScreen.preventAutoHideAsync();
export default function App() {
const {
initialized,
regulations,
confirmed,
welcomed,
updateConfirmation,
updateWelcomed,
} = useAppInitialization();
const onLayoutRootView = useCallback(async () => {
if (initialized) {
await SplashScreen.hideAsync();
}
}, [initialized]);
if (!initialized) {
return null;
}
return (
<SafeAreaProvider>
<PaperProvider theme={AppTheme}>
<NavigationContainer onReady={onLayoutRootView}>
<RegulationsContext.Provider
value={{
regulations,
confirmed,
welcomed,
updateConfirmation,
updateWelcomed,
}}
>
<Stack.Navigator
screenOptions={{
headerShown: false,
animation: "slide_from_right",
}}
>
<Stack.Screen
name="WaterbodyGroupList"
component={WaterbodyGroupList}
/>
<Stack.Screen
name="WaterbodyGroupDetails"
component={WaterbodyDetailsScreen}
/>
<Stack.Screen
name="WaterbodyGroupDetailsRegulation"
component={WaterbodyDetailsRegulationScreen}
/>
</Stack.Navigator>
</RegulationsContext.Provider>
</NavigationContainer>
{regulations.message && (
<Snackbar onDismiss={() => {}} visible>
{regulations.message}
</Snackbar>
)}
</PaperProvider>
</SafeAreaProvider>
);
}