-
Notifications
You must be signed in to change notification settings - Fork 11
/
application.js
128 lines (104 loc) · 3.25 KB
/
application.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
/**
* Created by maluramichael on 18/08/16.
*/
import React, { Component } from 'react';
import { StyleSheet, Text, View, AppRegistry } from 'react-native';
import BetterNavigator from 'react-native-better-navigator';
import LoadingOverlay from 'react-native-loading-overlay';
import Drawer from 'react-native-drawer';
import { connect } from 'react-redux';
import { Constants, Routes, Components, Data } from './app';
class Application extends Component {
//**********************************************
// Component
//**********************************************
constructor( props ) {
super( props );
this.router = this.router.bind( this );
this.toggleSideMenu = this.toggleSideMenu.bind( this );
this.onSideMenuOpen = this.onSideMenuOpen.bind( this );
this.onSideMenuClose = this.onSideMenuClose.bind( this );
this.onPressDrawerButton = this.onPressDrawerButton.bind( this );
const routes = [
[ Constants.Routes.DASHBOARD, Routes.Dashboard ]
];
this.routeMap = new Map( routes );
}
render() {
const { Loading, SideMenu } = this.props.Store;
const initialRoute = { name: Constants.Routes.DASHBOARD, title: 'Dashboard' };
const defaultComponents = {
left: ()=> <Components.MenuButton icon='bars' onPress={this.toggleSideMenu}/>
};
const scene = (
<View style={{flex: 1}}>
<BetterNavigator initialRoute={initialRoute}
routes={this.router}
defaultComponents={defaultComponents}
sceneStyle={{backgroundColor: 'white'}}
ref={'betterNavigator'}/>
<LoadingOverlay visible={Loading.loadingCount > 0} text={Loading.text}/>
</View>
);
const drawerStyles = {
drawer: { shadowRadius: 0 },
main : { paddingLeft: 0 },
};
const tweenHandler = ( ratio ) => ({
main: { opacity: (2 - ratio) / 2 }
});
return (
<Drawer ref={(drawer)=>this.drawer = drawer}
type="overlay"
content={<Components.Menu onPress={this.onPressDrawerButton}/>}
openDrawerOffset={0.4} // 20% gap on the right side of drawer
panCloseMask={0.5}
panThreshold={.25}
panOpenMask={0}
tapToClose={true}
tweenHandler={tweenHandler}
closedDrawerOffset={0}
styles={drawerStyles}
open={SideMenu.isOpen}
onOpen={this.onSideMenuOpen}
onClose={this.onSideMenuClose}>
{scene}
</Drawer>
);
}
//**********************************************
// Methods
//**********************************************
router( route ) {
if ( !route ) return null;
if ( !this.routeMap ) return null;
if ( !this.routeMap.has( route.name ) ) return null;
return this.routeMap.get( route.name );
}
toggleSideMenu() {
this.props.dispatch( Data.Actions.SideMenu.toggle() );
}
onSideMenuOpen() {
this.props.dispatch( Data.Actions.SideMenu.open() );
}
onSideMenuClose() {
this.props.dispatch( Data.Actions.SideMenu.close() );
}
onPressDrawerButton( route ) {
this.refs.betterNavigator.refs.navigator.resetTo( route );
setTimeout( ()=> {
this.props.dispatch( Data.Actions.SideMenu.close() );
}, 120 );
}
}
const stateSelector = state => {
return {
Store: {
Loading : state.Loading,
SideMenu: state.SideMenu
}
}
};
const connector = connect( stateSelector );
const connectedApplication = connector( Application );
export default connectedApplication;