-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathApp.tsx
More file actions
146 lines (131 loc) · 3.85 KB
/
App.tsx
File metadata and controls
146 lines (131 loc) · 3.85 KB
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
import React from "react";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { StatusBar } from "expo-status-bar";
import * as eva from "@eva-design/eva";
import { ApplicationProvider, IconRegistry } from "@ui-kitten/components";
import { useColorScheme } from "react-native";
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import { getLocales } from "expo-localization";
import mapping from "./style.json";
import ServerScreen from "./screens/ServerScreen";
import ServerManualScreen from "./screens/ServerManualScreen";
import MainScreen from "./screens/MainScreen";
import SettingsScreen from "./screens/SettingsScreen";
import { AppProvider, useAppContext } from "./components/AppContext";
import custom from "./themes.json";
import { useFonts } from "expo-font";
import { EvaIconsPack } from "@ui-kitten/eva-icons";
import * as SplashScreen from "expo-splash-screen";
import { decode, encode } from "base-64";
import translations from "./i18n";
import { RootStackParamList } from "types";
import { SCHEME } from "utils/constants";
if (!global.btoa) {
global.btoa = encode;
}
if (!global.atob) {
global.atob = decode;
}
SplashScreen.preventAutoHideAsync();
const Stack = createNativeStackNavigator<RootStackParamList>();
i18n.use(initReactI18next).init({
resources: translations,
lng: getLocales()[0].languageCode ?? undefined,
fallbackLng: "en",
});
const hideSplash = () => {
setTimeout(async () => {
await SplashScreen.hideAsync();
}, 500);
};
function AppNavigator() {
const { activeServer, isLoading } = useAppContext();
// Show splash/loading while determining initial route
if (isLoading) {
return null;
}
const sheetOpts = {
animation: "slide_from_bottom" as const,
presentation: "modal" as const,
};
return (
<NavigationContainer
onReady={hideSplash}
linking={{
prefixes: [SCHEME + "://"],
config: {
screens: {
ServerManual: {
path: "server",
parse: {
url: String,
username: String,
password: String,
},
},
},
},
}}
>
<Stack.Navigator
screenOptions={{
headerShown: false,
}}
>
{activeServer?.url ? (
<>
<Stack.Screen name="Main" component={MainScreen} />
<Stack.Screen
name="Settings"
component={SettingsScreen}
options={sheetOpts}
/>
<Stack.Screen
name="ServerManual"
component={ServerManualScreen}
options={sheetOpts}
/>
</>
) : (
<>
<Stack.Screen name="Server" component={ServerScreen} />
<Stack.Screen
name="ServerManual"
component={ServerManualScreen}
options={sheetOpts}
/>
</>
)}
</Stack.Navigator>
</NavigationContainer>
);
}
export default function App() {
const colorScheme = useColorScheme();
const theme: "light" | "dark" = colorScheme === "dark" ? "dark" : "light";
const [fontsLoaded] = useFonts({
"Montserrat-Bold": require("./assets/fonts/Montserrat-Bold.ttf"),
"Montserrat-Medium": require("./assets/fonts/Montserrat-Medium.ttf"),
});
const mergedTheme = { ...eva[theme], ...custom[theme] };
if (!fontsLoaded) {
return null;
}
return (
<>
<IconRegistry icons={EvaIconsPack} />
<AppProvider>
<ApplicationProvider
{...eva}
theme={mergedTheme}
customMapping={{ ...eva.mapping, ...mapping }}
>
<AppNavigator />
</ApplicationProvider>
</AppProvider>
<StatusBar style="auto" />
</>
);
}