-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.js
56 lines (52 loc) · 1.79 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import 'react-native-gesture-handler';
import React from 'react';
import MainNavigator from './src/navigator';
import {Provider} from 'react-redux';
import configureStore from './src/redux/store';
import {PersistGate} from 'redux-persist/integration/react';
import {Provider as PaperProvider} from 'react-native-paper';
import SplashScreen from 'react-native-splash-screen';
import messaging from '@react-native-firebase/messaging';
const App = (props) => {
const {store, persistor} = configureStore();
const [loading, setLoading] = React.useState(true);
const [initialRoute, setInitialRoute] = React.useState('Dashboard');
// const {isLogin, role} = useSelector((s) => s.Auth);
React.useEffect(() => {
SplashScreen.hide();
// Assume a message-notification contains a "type" property in the data payload of the screen to open
messaging().onNotificationOpenedApp((remoteMessage) => {
console.log(
'Notification caused app to open from background state:',
remoteMessage.notification,
);
props.navigation.navigate(remoteMessage.data.type);
});
// Check whether an initial notification is available
messaging()
.getInitialNotification()
.then((remoteMessage) => {
if (remoteMessage) {
console.log(
'Notification caused app to open from quit state:',
remoteMessage.notification,
);
setInitialRoute(remoteMessage.data.type); // e.g. "Settings"
}
setLoading(false);
});
}, [props.navigation]);
if (loading) {
return null;
}
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<PaperProvider>
<MainNavigator />
</PaperProvider>
</PersistGate>
</Provider>
);
};
export default App;