This repository has been archived by the owner on Dec 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
163 lines (150 loc) · 5.2 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import 'expo-dev-client';
import 'react-native-gesture-handler';
import { StatusBar } from 'expo-status-bar';
import * as Notifications from 'expo-notifications';
import * as Linking from 'expo-linking';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { Appearance } from 'react-native';
import * as SplashScreen from 'expo-splash-screen';
import { LinkingOptions, NavigationContainer, PathConfigMap } from '@react-navigation/native';
import { BottomNav } from './src/navigation/root/bottomNav';
import { BottomSheetModalProvider } from '@gorhom/bottom-sheet';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { getTheme } from './src/Storage/themeStorage';
import { useAnilistAuth } from './src/auth/auth';
import { RefreshContext, ThemeContext, AccountContext } from './src/contexts/context';
import useNotification from './src/Notifications/notifications';
import { Portal, Provider as PaperProvider } from 'react-native-paper';
import * as NavigationBar from 'expo-navigation-bar';
import { themeSwitch } from './src/Themes/themes';
import DownloadDialog from './src/Components/dialogs/downloadDialog';
import { useRelease } from './src/Api/github/github';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { enableFreeze } from 'react-native-screens';
import { Inter_900Black, useFonts } from '@expo-google-fonts/inter';
import * as Font from 'expo-font';
enableFreeze(true);
const prefix = Linking.createURL('/');
const config: PathConfigMap<ReactNavigation.RootParamList> = {
ExploreStack: {
screens: {
Explore: 'explore',
Info: {
path: 'info/:type/:id',
parse: {
id: Number,
}
},
StaffExplore: {
path: 'staff/:id',
parse: {
id: Number,
}
},
CharacterExplore: {
path: 'character/:id',
parse: {
id: Number,
}
}
}
},
MoreStack: {
screens: {
AccountStack: {
screens: {
AccountHome: {
path: 'auth/:token?',
parse: {
access_token: (token) => `${token}`,
},
}
}
}
}
}
}
// Notifications.setNotificationHandler({
// handleNotification: async () => ({
// shouldShowAlert: true,
// shouldPlaySound: false,
// shouldSetBadge: true,
// }),
// });
const App = () => {
const systemTheme = Appearance.getColorScheme();
let [fontsLoaded] = useFonts({Inter_900Black,})
const [appReady, setAppReady] = useState<boolean>(false);
const [theme, setTheme] = useState((systemTheme === 'light') ? 'Light' : 'Dark');
const [refresh, setRefresh] = useState();
const [showDialog, setShowDialog] = useState<boolean>(false);
const { newVersion } = useRelease();
const { isAuth, setIsAuth } = useAnilistAuth();
// const {receivedSubscription, responseSubscription} = useNotification(isAuth);
const valueReset = useMemo(() => ({ refresh, setRefresh }), [refresh]);
const valueAuth = useMemo(() => ({ isAuth, setIsAuth }), [isAuth]);
const value = useMemo(() => ({ theme, setTheme }), [theme]);
const linking: LinkingOptions<ReactNavigation.RootParamList> = {
prefixes: [prefix],
config: { screens: config },
}
const prepare = async() => {
try{
await SplashScreen.preventAutoHideAsync();
await Font.loadAsync({Inter_900Black});
} catch(e) {
console.log('Start Error:', e);
} finally {
setAppReady(true);
}
}
const onLayoutRoot = useCallback(async() => {
if (appReady) {
await SplashScreen.hideAsync();
}
}, [appReady]);
useEffect(() => {
getTheme().then(theme => { (theme !== null) ? setTheme(theme) : setTheme((systemTheme === 'light') ? 'Light' : 'Dark'); });
}, [isAuth]);
useEffect(() => {
if (newVersion.isNew) {
setShowDialog(true);
}
}, [newVersion.isNew]);
useEffect(() => {
prepare();
// return () => {
// receivedSubscription.remove();
// responseSubscription.remove();
// }
}, []);
if (!appReady) {
return null;
}
return (
<PaperProvider>
<SafeAreaProvider>
<GestureHandlerRootView style={{ flex: 1 }}>
{/* @ts-ignore */}
<RefreshContext.Provider value={valueReset}>
<ThemeContext.Provider value={value}>
<AccountContext.Provider value={valueAuth}>
<BottomSheetModalProvider>
{/* @ts-ignore */}
<NavigationContainer onReady={onLayoutRoot} linking={linking} theme={themeSwitch(theme)}>
<BottomNav isAuth={isAuth} />
<StatusBar style={(theme.toLowerCase().includes('dark')) ? "light" : "dark"} translucent />
<Portal>
<DownloadDialog release={newVersion.release} visible={showDialog} onDismiss={() => setShowDialog(false)} colors={themeSwitch(theme).colors} />
</Portal>
</NavigationContainer>
</BottomSheetModalProvider>
</AccountContext.Provider>
</ThemeContext.Provider>
</RefreshContext.Provider>
</GestureHandlerRootView>
</SafeAreaProvider>
</PaperProvider>
);
}
export default App;