-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
118 lines (100 loc) · 3.12 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
import React from 'react'
import { BackHandler, StyleSheet, View, ScrollView } from 'react-native'
import { Root, Container, Header, Content, Spinner } from 'native-base'
import Expo, { Constants } from 'expo'
import { StackNavigator, addNavigationHelpers, NavigationActions } from 'react-navigation'
import { Provider, connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import getStore from './src/store'
import { isDoneWorking } from './src/actions'
import { getIsWorking } from './src/reducers'
import styles from './src/assets/styles/common'
// Screens
import Login from './src/containers/Login'
import Menu from './src/containers/Menu'
import Services from './src/containers/Services'
import Insurance from './src/containers/Insurance'
import UpdateStore from './src/containers/UpdateStore'
import Payment from './src/containers/Payment'
import Loading from './src/components/Loading'
const AppNavigator = StackNavigator({
Login: { screen: Login },
Menu: { screen: Menu },
Services: { screen: Services },
Insurance: { screen: Insurance },
Payment: { screen: Payment },
UpdateStore: { screen: UpdateStore },
}, { headerMode: 'none' })
const initialState = AppNavigator.router.getStateForAction(AppNavigator.router.getActionForPathAndParams('Login'))
const navReducer = (state = initialState, action) => {
const newState = AppNavigator.router.getStateForAction(action, state)
return newState || state
}
class BaseApp extends React.Component {
constructor(props) {
super(props)
}
async componentWillMount() {
try {
await Expo.Font.loadAsync({
'Roboto': require('native-base/Fonts/Roboto.ttf'),
'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'),
'Ionicons': require('@expo/vector-icons/fonts/Ionicons.ttf'),
});
this.props.makeReady()
} catch(e) {
console.log(e)
}
}
componentDidMount() {
BackHandler.addEventListener("hardwareBackPress", this.onBackPress);
}
componentWillUnmount() {
BackHandler.removeEventListener("hardwareBackPress", this.onBackPress);
}
onBackPress = () => {
const { dispatch, nav } = this.props
if (nav.index === 0) {
return false
}
dispatch(NavigationActions.back())
return true
}
render() {
console.log(this.props)
const { dispatch, nav } = this.props
if(!this.props.isReady) return (<Loading />)
return (
<Root>
<AppNavigator navigation={addNavigationHelpers({
dispatch: dispatch,
state: nav,
})} />
</Root>
);
}
}
const mapStateToProps = (state) => ({
nav: state.nav,
isReady: getIsWorking(state)
});
const mapDispatchToProps = (dispatch) => {
return {
// actions: bindActionCreators(actions, dispatch)
makeReady: () => dispatch(isDoneWorking()),
dispatch
};
}
const AppWithNavigationState = connect(mapStateToProps, mapDispatchToProps)(BaseApp);
const store = getStore(navReducer)
export default class App extends React.Component {
render() {
return (
<Root>
<Provider store={store}>
<AppWithNavigationState />
</Provider>
</Root>
)
}
}