-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
42 lines (36 loc) · 1.27 KB
/
App.js
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
import { StatusBar } from 'expo-status-bar';
import React, { useContext, useState, useEffect } from 'react';
import { AsyncStorage } from 'react-native';
import {
NavigationContainer,
DefaultTheme,
DarkTheme,
} from '@react-navigation/native';
import { StyleSheet, Text, View } from 'react-native';
import messaging from '@react-native-firebase/messaging';
import { ThemeProvider } from './src/components/ThemeContext';
import Navigator from './src/components/Navigator';
export default function App() {
const [theme, setTheme] = useState(DefaultTheme);
useEffect(async () => {
messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log('Message handled in the background!', remoteMessage);
});
const unSubscribe = messaging().subscribeToTopic('general').then(() => console.log('Subscribed to topic!'));
const userTheme = await AsyncStorage.getItem('theme');
console.log('userTheme', userTheme);
if (userTheme) {
const newTheme = JSON.parse(userTheme);
if (theme !== newTheme)
setTheme(newTheme);
}
return unSubscribe;
}, []);
return (
<ThemeProvider value={{ theme, setTheme }}>
<NavigationContainer theme={theme} >
<Navigator />
</NavigationContainer>
</ThemeProvider>
);
}