-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
126 lines (116 loc) · 3.58 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react'
import {
StatusBar,
View,
AppState,
Keyboard,
NetInfo
} from 'react-native'
import crashlytics from 'react-native-fabric-crashlytics'
import Router from './app/Router'
import currencyStore from './app/AppStores/CurrencyStore'
import NavStore from './app/AppStores/NavStore'
import BlindScreen from './app/components/screens/BlindScreen'
import Spinner from './app/components/elements/Spinner'
import MainStore from './app/AppStores/MainStore'
import NotificationStore from './app/AppStores/stores/Notification'
import PushNotificationHelper from './app/commons/PushNotificationHelper'
import AppStyle from './app/commons/AppStyle'
console.ignoredYellowBox = ['Warning: isMounted']
export default class App extends Component {
async componentWillMount() {
await MainStore.startApp()
NetInfo.addEventListener(
'connectionChange',
this.handleFirstConnectivityChange
)
}
async componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange)
crashlytics.init()
try {
// SplashScreen.hide()
await currencyStore.getCurrencyAPI()
} catch (e) {
NavStore.popupCustom.show(e.message)
// SplashScreen.hide()
}
}
componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange)
}
handleFirstConnectivityChange = (connection) => {
const connectionType = connection.type === 'none' ? 'offline' : 'online'
if (connection.type === 'none') {
NavStore.showToastTop('No internet connection', { backgroundColor: AppStyle.errorColor }, { color: 'white' })
}
MainStore.appState.setInternetConnection(connectionType)
}
switchEnableNotification(isEnable) {
if (MainStore.appState.internetConnection === 'offline') {
NavStore.popupCustom.show('Network Error.')
return
}
if (isEnable) {
NotificationStore.onNotif().then(res => console.log(res))
} else {
NotificationStore.offNotif().then(res => console.log(res))
}
}
appState = 'active'
_handleAppStateChange = (nextAppState) => {
if (this.appState === 'active' && nextAppState === 'inactive') {
if (NavStore.currentRouteName !== 'UnlockScreen') {
this.blind.showBlind()
}
}
if (nextAppState === 'inactive' || nextAppState === 'background') {
Keyboard.dismiss()
}
if (nextAppState === 'background') {
NotificationStore.appState = nextAppState
}
if (nextAppState === 'active') {
setTimeout(() => { NotificationStore.appState = nextAppState }, 2000)
// MainStore.appState.BgJobs.CheckBalance.doOnce(false, false)
MainStore.appState.BgJobs.CheckBalance.start()
this.blind.hideBlind()
}
if (this.appState === 'background' && nextAppState === 'active') {
PushNotificationHelper.resetBadgeNumber()
NavStore.lockScreen({
onUnlock: () => {
if (NotificationStore.isOpenFromTray) {
NotificationStore.isOpenFromTray = false
NotificationStore.gotoTransaction()
}
}
})
}
this.appState = nextAppState
}
render() {
return (
<View style={{ flex: 1 }}>
<StatusBar
backgroundColor="transparent"
barStyle="light-content"
translucent
/>
<Router />
<BlindScreen
ref={(ref) => { this.blind = ref }}
/>
<Spinner
visible={false}
ref={(ref) => { NavStore.loading = ref }}
/>
</View>
)
}
}