-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAppWrapper.js
More file actions
51 lines (46 loc) · 1.27 KB
/
AppWrapper.js
File metadata and controls
51 lines (46 loc) · 1.27 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
import React, { useEffect } from 'react';
import { AppState } from 'react-native';
import { Provider } from 'react-redux';
import { Root } from 'native-base';
import store from './store';
import AppNavigator from './AppNavigator';
import { clearNotifications } from './PushNotification';
import { Service } from './Service';
import { getPushToken } from './PushNotification';
const AppWrapper: () => React$Node = () => {
const _handleAppStateChange = state => {
// clear notifications when app active
if (state === 'active') {
clearNotifications();
}
};
const _initPush = async () => {
const authenticator = await Service.get();
const pairings = await authenticator.getPairings();
if (pairings.length > 0) {
const token = await getPushToken();
if (token) {
authenticator.setPushToken(token);
}
}
};
// monitor app state
useEffect(() => {
AppState.addEventListener('change', _handleAppStateChange);
return () => {
AppState.removeEventListener('change', _handleAppStateChange);
};
}, []);
// update push token
useEffect(() => {
_initPush();
}, []);
return (
<Provider store={store}>
<Root>
<AppNavigator />
</Root>
</Provider>
);
};
export default AppWrapper;