-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
64 lines (52 loc) · 1.94 KB
/
App.js
File metadata and controls
64 lines (52 loc) · 1.94 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
import React, {useState, useEffect} from 'react';
import { AuthContextProvider } from './src/context/AuthContext';
import Routes from './Routes';
import { UserProfileContext } from './src/context/UserProfileContext';
import { NotificationNumberContext } from './src/context/NotificationNumberContext';
import { ThemeContext } from './src/context/ThemeContext';
import { Appearance } from "react-native";
import 'react-native-gesture-handler';
import { useFonts } from 'expo-font';
import * as SplashScreen from 'expo-splash-screen';
// To wait for font to load.
SplashScreen.preventAutoHideAsync();
const App = () => {
const [userProfile, setUserProfile] = useState({});
const [notificationNumber, setNotificationNumber] = useState(0);
const [theme, setTheme] = useState({ mode: Appearance.getColorScheme() });
useEffect(() => {
//updateTheme called via Appearance.addChangeListener method upon theme change
Appearance.addChangeListener(({ colorScheme }) => {
setTheme({ mode: colorScheme });
});
}, []);
// Load Fonts CHANGE FONT HERE
const [fontsLoaded] = useFonts({
'customFont': require('./src/assets/fonts/Inter-Bold.otf'),
});
// console.log('current theme:', theme.mode);
// console.log(fontsLoaded);
// Display Splash Screen till fonts are loaded, then hide splash
useEffect(() => {
const hide = async () => {
if (fontsLoaded) {
await SplashScreen.hideAsync();
}}
hide();
}, [fontsLoaded]);
if (!fontsLoaded) {
return null;
}
return (
<AuthContextProvider>
<UserProfileContext.Provider value={[userProfile, setUserProfile]}>
<NotificationNumberContext.Provider value={[notificationNumber, setNotificationNumber]}>
<ThemeContext.Provider value={{ theme }}>
<Routes />
</ThemeContext.Provider>
</NotificationNumberContext.Provider>
</UserProfileContext.Provider>
</AuthContextProvider>
);
};
export default App;