-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
155 lines (138 loc) · 4.5 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
153
154
155
import 'react-native-gesture-handler';
import React from 'react';
import {LogBox, Platform, StatusBar, View} from 'react-native';
import {Provider} from 'react-redux';
import {PersistGate} from 'redux-persist/integration/react';
import {persistStore} from 'redux-persist';
import {store} from './src/store';
import axios from 'axios';
import crashlytics from '@react-native-firebase/crashlytics';
import BaseStyle from './src/styles/BaseStyle';
import RootStackNavigator from './src/routes/RootStackNavigator';
import {NativeBaseProvider, Text, Box, extendTheme} from 'native-base';
import Toast from 'react-native-toast-message';
import {console_log} from './src/utils/Misc';
import {Config} from './src/utils/Constants';
import './IgnoreWarnings';
import SplashScreen from 'react-native-splash-screen';
import messaging from '@react-native-firebase/messaging';
import MaintenanceAndUpdate from './src/components/MaintenanceAndUpdate';
import ErrorBoundary from 'react-native-error-boundary';
////////////////////////////////////////////////////////////////////////////////
store.subscribe(listener);
function select(state) {
//console_log("state:", state);
const {token} = state.auth.user;
if (token === undefined || token === '') return '';
return token;
}
function listener() {
let token = select(store.getState());
//console_log("Authorization token:", token);
axios.defaults.headers.common['Content-Type'] =
'application/json; charset=UTF-8';
if (token === '') {
delete axios.defaults.headers.common['Authorization'];
} else {
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token;
}
}
//axios.defaults.baseURL = Config.SERVER_API_URL;
//////////////////////////////////////////////////////////////////////////////////////
const persistor = persistStore(store);
const config = {
useSystemColorMode: false,
initialColorMode: 'light',
fontConfig: {
AlrightSans: {
100: {
normal: 'AlrightSans-Light',
italic: 'AlrightSans-LightItalic',
},
200: {
normal: 'AlrightSans-Regular',
italic: 'AlrightSans-RegularItalic',
},
300: {
normal: 'AlrightSans-Medium',
italic: 'AlrightSans-MediumItalic',
},
400: {
normal: 'AlrightSans-Bold',
italic: 'AlrightSans-BoldItalic',
},
500: {
normal: 'AlrightSans-Ultra',
italic: 'AlrightSans-UltraItalic',
},
},
fonts: {
heading: 'AlrightSans',
body: 'AlrightSans',
mono: 'AlrightSans',
customFont: 'AlrightSans',
},
},
};
const app11Theme = extendTheme({config: config});
async function requestUserPermission() {
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) {
console.log('Authorization status:', authStatus);
}
}
const App = () => {
//Hide Splash screen on app load.
React.useEffect(() => {
SplashScreen.hide();
// IF IOS THEN REQUEST PUSH NOTIFICATION PERMISSION
if (Platform.OS === 'ios') requestUserPermission();
});
React.useEffect(() => {
const unsubscribe = messaging().onMessage(async remoteMessage => {
Alert.alert('A new FCM message arrived!', JSON.stringify(remoteMessage));
});
return unsubscribe;
}, []);
const errorHandler = props => {
/** SEND LOGS TO CRASHLYTICS */
const {error, stackTrace} = props;
crashlytics().log(error);
crashlytics().log(`STACK_TRACE: ${stackTrace}`);
};
const CustomFallback = props => (
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}>
<Text>Something happened!</Text>
<Text>{props.error.toString()}</Text>
<Button onPress={props.resetError} title={'Try again'} />
</View>
);
// USE ERROR BOUNDARY TO CAPTURE ERROR HAPPENING INSIDE THE APP
return (
<ErrorBoundary FallbackComponent={CustomFallback} onError={errorHandler}>
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<NativeBaseProvider safeArea theme={app11Theme}>
<StatusBar
backgroundColor={'transparent'}
translucent={true}
barStyle="dark-content"
/>
<RootStackNavigator />
<Toast />
<MaintenanceAndUpdate />
</NativeBaseProvider>
</PersistGate>
</Provider>
</ErrorBoundary>
);
};
export default App;