Repository navigation
Expand file tree
/
Copy pathExample.js
More file actions
234 lines (223 loc) · 8.78 KB
/
Copy pathExample.js
File metadata and controls
234 lines (223 loc) · 8.78 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import React, {
Component,
} from 'react';
import {
StyleSheet,
Text,
View,
} from 'react-native';
import Launch from './components/Launch';
import Register from './components/Register';
import Login from './components/Login';
import Login2 from './components/Login2';
import Login3 from './components/Login3';
import {
Scene,
Reducer,
Router,
Switch,
Modal,
Actions,
ActionConst,
} from 'react-native-router-flux';
import Error from './components/Error';
import Home from './components/Home';
import TabView from './components/TabView';
import TabIcon from './components/TabIcon';
import EchoView from './components/EchoView';
import NavigationDrawer from './components/NavigationDrawer';
import Button from 'react-native-button';
const styles = StyleSheet.create({
container: {
flex: 1, backgroundColor: 'transparent', justifyContent: 'center',
alignItems: 'center',
},
tabBarStyle: {
backgroundColor: '#2d3e63',
},
tabBarSelectedItemStyle: {
backgroundColor: '#2d4f60'
},
});
const purgeAll = (object, target) => {
if (object.children) {
const keys = Object.keys(target)
// overide the children array with the new purged array
object.children = object.children.filter(obj =>
// ignore the matching object
!keys.every(key => target[key] === obj[key]) && purgeAll(obj, target)
)
}
return object
}
const reducerCreate = params => {
const defaultReducer = new Reducer(params);
return (state, action) => {
// make sure state and scene exist
if(state && action.scene) {
// once we have gone to scene "register2" delete the modal
if(action.scene.sceneKey === 'register2') {
// purge modal scene from the child arrays
purgeAll(state, {
key: 'error_1_error',
sceneKey: 'error'
})
}
}
return defaultReducer(state, action)
}
}
// define this based on the styles/dimensions you use
const getSceneStyle = (/* NavigationSceneRendererProps */ props, computedProps) => {
const style = {
flex: 1,
backgroundColor: '#fff',
shadowColor: null,
shadowOffset: null,
shadowOpacity: null,
shadowRadius: null,
};
if (computedProps.isActive) {
style.marginTop = computedProps.hideNavBar ? 0 : 64;
style.marginBottom = computedProps.hideTabBar ? 0 : 50;
}
return style;
};
let currentSwitchPage = 'text1';
const SwitcherPage = (props) => (
<View>
<Text style={{ marginTop: 100, textAlign: 'center' }}>current page: {props.text}</Text>
<Button
onPress={() => {
currentSwitchPage = currentSwitchPage === 'text1' ? 'text2' : 'text1';
Actions.refresh({ key: 'switcher' });
}}
>
Switch!
</Button>
<Button
onPress={() => {
Actions.launch({ type: ActionConst.RESET });
}}
>
Exit
</Button>
</View>
);
class Example extends Component {
componentDidMount() {
// open the modal dialog once so the componts mounts but it won't show
//Actions.error()
//console.log('Error modal component mounted!')
}
render() {
return (
<Router createReducer={reducerCreate} getSceneStyle={getSceneStyle}>
<Scene key="modal" component={Modal}>
<Scene key="root" hideNavBar hideTabBar>
<Scene key="echo" clone component={EchoView} getTitle={(navState) => navState.key}/>
<Scene
key="switcher"
component={Switch}
selector={() => { return 'text1'; }}
>
<Scene
key="text1"
text="text1"
component={(props) => <SwitcherPage
{...props}
text={currentSwitchPage}
/>}
/>
<Scene
key="text2"
text="text2"
component={(props) => <SwitcherPage
{...props}
text={currentSwitchPage}
/>}
/>
</Scene>
<Scene key="register" component={Register} title="Register"/>
<Scene key="register2" component={Register} title="Register2" duration={1}/>
<Scene key="home" component={Home} title="Replace" type={ActionConst.REPLACE}/>
<Scene key="launch" component={Launch} title="Launch" initial/>
<Scene key="login" direction="vertical">
<Scene key="loginModal" direction="vertical" component={Login} title="Login"/>
<Scene
key="loginModal2"
hideNavBar
component={Login2}
title="Login2"
panHandlers={null}
duration={1}
/>
<Scene
key="loginModal3"
hideNavBar
component={Login3}
title="Login3"
panHandlers={null}
duration={1}
/>
</Scene>
<Scene key="tabbar">
<Scene
key="main"
tabs
tabBarStyle={styles.tabBarStyle}
tabBarSelectedItemStyle={styles.tabBarSelectedItemStyle}
>
<Scene
key="tab1"
initial
title="First Tab"
icon={TabIcon}
navigationBarStyle={{ backgroundColor: 'white'}}
titleStyle={{ color: 'black' }}
>
<Scene
key="tab1_1"
component={TabView}
title="Tab #1_1"
onRight={() => alert('Right button')}
rightTitle="Right"
/>
<Scene
key="tab1_2"
component={TabView}
title="Tab #1_2"
titleStyle={{ color: 'white' }}
/>
</Scene>
<Scene key="tab2" title="Tab #2" icon={TabIcon}>
<Scene
key="tab2_1"
component={TabView}
title="Tab #2_1"
renderRightButton={() => <Text>Right</Text>}
/>
<Scene
key="tab2_2"
component={TabView}
title="Tab #2_2"
hideBackImage
onBack={() => alert('Left button!')}
backTitle="Left"
duration={1}
panHandlers={null}
/>
</Scene>
<Scene key="tab3" component={TabView} title="Tab #3" icon={TabIcon}/>
<Scene key="tab4" component={TabView} title="Tab #4" hideNavBar icon={TabIcon}/>
<Scene key="tab5" component={TabView} title="Tab #5" hideTabBar icon={TabIcon}/>
</Scene>
</Scene>
</Scene>
<Scene key="error" component={Error}/>
</Scene>
</Router>
);
}
}
export default Example;