forked from DiscipleTools/disciple-tools-mobile-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
152 lines (136 loc) · 5.07 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
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
import React, { useState, useRef, useEffect } from 'react';
import { LogBox, Platform, StatusBar, StyleSheet, View } from 'react-native';
import NetInfo from '@react-native-community/netinfo';
import PropTypes from 'prop-types';
import AppLoading from 'expo-app-loading';
import * as Notifications from 'expo-notifications';
import Constants from 'expo-constants';
import * as Icon from '@expo/vector-icons';
import * as Font from 'expo-font';
import { Asset } from 'expo-asset';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react';
//import Reactotron from 'reactotron-react-native';
//import * as Sentry from 'sentry-expo';
import AppNavigator from './navigation/AppNavigator';
import { store, persistor } from './store/store';
import sharedTools from './shared';
// notifications
import { networkStatus, setNetworkConnectivity } from './store/actions/networkConnectivity.actions';
/*Sentry.init({
dsn: 'https://aaa9d833ba5942d59c69e290ffbd3f36@o424480.ingest.sentry.io/5356329',
enableInExpoDevelopment: true,
debug: true,
});*/
import { styles } from './App.styles';
export default function App() {
const [state, setState] = useState({
isLoadingComplete: false,
});
const [notification, setNotification] = useState(false);
const notificationListener = useRef();
const responseListener = useRef();
// push notification listeners
useEffect(() => {
notificationListener.current = Notifications.addNotificationReceivedListener((notification) => {
setNotification(notification);
});
responseListener.current = Notifications.addNotificationResponseReceivedListener((response) => {
console.log('********** NOTIFICATION RESPONSE RECEIVED **********');
console.log(response);
});
return () => {
Notifications.removeNotificationSubscription(notificationListener);
Notifications.removeNotificationSubscription(responseListener);
};
}, []);
// network connectivity listeners
useEffect(() => {
NetInfo.fetch().then((state) => {
handleConnectivityChange(state.isConnected);
});
unsubscribe = NetInfo.addEventListener((state) =>
sharedTools.onlyExecuteLastCall(state.isConnected, handleConnectivityChange, 1000),
);
//if (__DEV__) {
// Reactotron can be used to see AsyncStorage data and API requests
// If Reactotron gets no connection, this is the solution that worked for me (cairocoder01: 2019-08-15)
// https://github.com/expo/expo-cli/issues/153#issuecomment-358925525
// May need to then run this before `npm start`: `adb reverse tcp:9090 tcp:9090`
//Reactotron.configure() // controls connection & communication settings
// .useReactNative() // add all built-in react native plugins
// .connect(); // let's connect!
//}
return () => {
unsubscribe();
};
}, []);
handleConnectivityChange = (isConnected) => {
// detect conectivity change (This only says if a device has an active connection, not that it is able to reach the internet)
if (isConnected) {
// Check if the phone has internet
fetch('https://8.8.8.8')
.then(() => {
store.dispatch(setNetworkConnectivity(true));
store.dispatch(networkStatus(true));
})
.catch(() => {
store.dispatch(setNetworkConnectivity(false));
store.dispatch(networkStatus(false));
});
} else {
store.dispatch(setNetworkConnectivity(false));
store.dispatch(networkStatus(false));
}
};
loadResourcesAsync = async () => {
/*
Promise.all([
Asset.loadAsync([
require('./assets/images/robot-dev.png'),
require('./assets/images/robot-prod.png'),
]),
Font.loadAsync({
// This is the font that we are using for our tab bar
...Icon.Ionicons.font,
// We include SpaceMono because we use it in HomeScreen.js. Feel free
// to remove this if you are not using it in your app
'space-mono': require('./assets/fonts/SpaceMono-Regular.ttf'),
}),
]);
*/
};
handleLoadingError = (error) => {
// In this case, you might want to report the error to your error
// reporting service, for example Sentry
// eslint-disable-next-line no-console
console.warn(error);
};
handleFinishLoading = () => {
setState({ isLoadingComplete: true });
// Initialize language from redux store after it has been hydrated
// const state = store.getState();
// i18n.setLocale(state.i18nReducer.locale);
};
if (!state.isLoadingComplete) {
return (
<AppLoading
startAsync={loadResourcesAsync}
onError={handleLoadingError}
onFinish={handleFinishLoading}
/>
);
}
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<View style={styles.container}>
{Platform.OS === 'ios' && <StatusBar barStyle="default" />}
<AppNavigator />
</View>
</PersistGate>
</Provider>
);
}
//LogBox.ignoreAllLogs();
LogBox.ignoreLogs(['Warning:', 'Animated:', 'VirtualizedLists', 'console.disableYellowBox']);