forked from ACE-IoT-Solutions/open-hems-app
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.tsx
executable file
·86 lines (75 loc) · 3.3 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
import React, { useEffect } from "react";
import { Platform, StatusBar } from "react-native";
import * as SplashScreen from "expo-splash-screen";
import { NavigationContainer } from "@react-navigation/native";
import { getStorageMacAddress, getWelcomeDismissed } from "./utils/api";
import { AppNavigator } from "./navigators/AppNavigator";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { ErrorBoundary } from "./components/ErrorBoundary";
import { theme } from "./theme";
import { WelcomeScreen } from "./screens/WelcomeScreen";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { AppScreenParamsList } from "./types";
import { MacAddressScreen } from "./screens/MacAddressScreen";
import { OptionsMenuScreen } from "./screens/OptionsMenuScreen";
import { SettingsScreen } from "./screens/SettingsScreen";
import { AuthTokenScreen } from "./screens/AuthTokenScreen";
import { useInitialRouteName, useWelcomeDismissed } from "./hooks/useAppStateData";
import {
Arimo_400Regular,
Arimo_500Medium,
Arimo_600SemiBold,
Arimo_700Bold,
useFonts,
} from "@expo-google-fonts/arimo";
SplashScreen.preventAutoHideAsync();
const { Navigator, Screen } = createNativeStackNavigator<AppScreenParamsList>();
function MainNavigator({ initialRouteName: initialRouteName }: { initialRouteName: keyof AppScreenParamsList }) {
const headerTintColor = theme.text;
const headerTitleStyle = {
fontFamily: theme.fonts.title,
};
return (
<Navigator initialRouteName={initialRouteName}>
<Screen name="WelcomeScreen" component={WelcomeScreen} options={{ headerShown: false }} />
<Screen name="MacAddress" component={MacAddressScreen} options={{ animation: "none", headerShown: false }} />
<Screen name="AppNavigator" component={AppNavigator} options={{ animation: "none", headerShown: false }} />
<Screen name="Options" component={OptionsMenuScreen} />
<Screen name="SettingsScreen" component={SettingsScreen} options={{ headerTintColor, headerTitleStyle }} />
<Screen name="AuthTokenScreen" component={AuthTokenScreen} options={{ headerTintColor, headerTitleStyle }} />
</Navigator>
);
}
export default function App() {
// const { welcomeDismissedState, error, loading, getWelcomeDismissedState, setWelcomeDismissedEffect } = useWelcomeDismissed();
// const initialRouteName = welcomeDismissedState ? "AppNavigator" : "WelcomeScreen" as keyof AppScreenParamsList;
const { initialRouteNameState, error, loading, getInitialRouteName } = useInitialRouteName();
const [fontsLoaded] = useFonts({
Arimo_400Regular,
Arimo_500Medium,
Arimo_600SemiBold,
Arimo_700Bold,
});
console.log("app.tsx", initialRouteNameState);
useEffect(() => {
StatusBar.setBarStyle("dark-content");
if (Platform.OS === "android") {
StatusBar.setBackgroundColor(theme.background);
}
// getInitialRouteName();
});
if (!fontsLoaded || loading) {
return;
} else {
SplashScreen.hideAsync();
return (
<ErrorBoundary>
<SafeAreaProvider>
<NavigationContainer>
<MainNavigator initialRouteName={initialRouteNameState} />
</NavigationContainer>
</SafeAreaProvider>
</ErrorBoundary>
);
}
}