-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathApp.tsx
141 lines (124 loc) · 3.86 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
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
import React, { useEffect } 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 { Appearance } 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 { ThemeContext } from "./components/ThemeContext";
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';
if (!global.btoa) {
global.btoa = encode;
}
if (!global.atob) {
global.atob = decode;
}
SplashScreen.preventAutoHideAsync();
const Stack = createNativeStackNavigator();
i18n.use(initReactI18next).init({
resources: translations,
lng: getLocales()[0].languageCode,
fallbackLng: "en",
});
function AppNavigator() {
const { serverUrl } = useAppContext();
//updateServerUrl("");
return (
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerShown: false,
}}
>
{serverUrl ? (
<>
<Stack.Screen name="Main" component={MainScreen} />
<Stack.Screen
name="Settings"
component={SettingsScreen}
options={{
animation: "slide_from_bottom",
presentation: "modal",
}}
/>
</>
) : (
<>
<Stack.Screen name="Server" component={ServerScreen} />
<Stack.Screen
name="ServerManual"
component={ServerManualScreen}
options={{
animation: "slide_from_bottom",
presentation: "modal",
}}
/>
</>
)}
</Stack.Navigator>
</NavigationContainer>
);
}
export default function App() {
const colorScheme = Appearance.getColorScheme();
const [theme, setTheme] = React.useState(colorScheme);
const [fontsLoaded] = useFonts({
"Montserrat-Bold": require("./assets/fonts/Montserrat-Bold.ttf"),
"Montserrat-Medium": require("./assets/fonts/Montserrat-Medium.ttf"),
});
// hide splash screen after 750ms
useEffect(() => {
setTimeout(async () => {
await SplashScreen.hideAsync();
}, 750);
}, []);
const toggleTheme = () => {
const nextTheme = theme === "light" ? "dark" : "light";
setTheme(nextTheme);
};
useEffect(() => {
const subscription = Appearance.addChangeListener(({ colorScheme }) => {
setTheme(colorScheme);
});
return () => subscription.remove();
}, []);
const mergedTheme = { ...eva[theme], ...custom[theme] };
if (!fontsLoaded) {
return null;
}
return (
<>
<IconRegistry icons={EvaIconsPack} />
<AppProvider>
<ThemeContext.Provider value={{ theme, toggleTheme }}>
<ApplicationProvider
{...eva}
theme={mergedTheme}
customMapping={{ ...eva.mapping, ...mapping }}
>
<AppNavigator />
</ApplicationProvider>
</ThemeContext.Provider>
</AppProvider>
<StatusBar
style={theme === "dark" ? "light" : "dark"}
backgroundColor={theme === "dark" ? "#010322" : "#f3f3f7"}
translucent={false}
/>
</>
);
}