-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathApp.js
79 lines (68 loc) · 1.91 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, {Component} from 'react';
import {Platform, StyleSheet, View, AppState} from 'react-native';
import {Root} from 'native-base'
import store from './app/store'
import {Provider,connect} from 'react-redux'
import DashboardView from './app/DashBoardView'
//components
import Loading from './app/components/Loading'
//cache
import appStorage from './app/cache/appStorage'
//hot reload
import codePush from 'react-native-code-push'
import {addListener} from './app/utils/navigationWithRedux'
class App extends Component < {} > {
componentWillMount = () => {
appStorage.getLoginUserJsonData((error, data) => {
if (error === null) {
if (store.getState().auth.username === null) {
store.dispatch({type: 'LOGIN', username: data})
}
}
})
// appStorage.removeAll()
appStorage.getShopListData((error, data) => {
if (error === null) {
if (data !== null) {
store.dispatch({type: 'STOCK_SHOP', data: data.data})
}
}
})
//theme
appStorage.getTheme((error, data) => {
if (error === null) {
if (data !== null) {
// console.log(data)
store.dispatch({type: 'CHANGE_THEME', theme: data})
}
}
})
}
componentDidMount = () => {
AppState.addEventListener('change', this._handleAppStateChange)
}
componentWillUnmount = () => {
AppState.removeEventListener('change', this._handleAppStateChange);
}
_handleAppStateChange = (nextAppState) => {
if (nextAppState.match(/inactive/)) {
appStorage.setShopListData()
// return
}
// this.setState({currentAppState: nextAppState});
// console.log(nextAppState)
}
render() {
return (<Root>
<Provider store={store}>
<DashboardView />
</Provider>
</Root>);
}
}
export default codePush(App)