forked from aksonov/react-native-router-flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample.js
214 lines (206 loc) · 6.29 KB
/
Example.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
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
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,
} 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 Right = () => (
<Text
style={{
width: 80,
height: 37,
position: 'absolute',
bottom: 4,
right: 2,
padding: 8,
}}
>Right</Text>
);
const styles = StyleSheet.create({
container: { flex: 1, backgroundColor: 'transparent', justifyContent: 'center',
alignItems: 'center',
},
tabBarStyle: {
backgroundColor: '#eee',
},
tabBarSelectedItemStyle: {
backgroundColor: '#ddd',
},
});
const reducerCreate = params => {
const defaultReducer = new Reducer(params);
return (state, action) => {
console.log('ACTION:', action);
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: 'reset' });
}}
>
Exit
</Button>
</View>
);
class Example extends Component {
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="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" component={NavigationDrawer}>
<Scene
key="main"
tabs
tabBarStyle={styles.tabBarStyle}
tabBarSelectedItemStyle={styles.tabBarSelectedItemStyle}
>
<Scene
key="tab1"
title="Tab #1"
icon={TabIcon}
navigationBarStyle={{ backgroundColor: 'red' }}
titleStyle={{ color: 'white' }}
>
<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: 'black' }}
/>
</Scene>
<Scene key="tab2" initial title="Tab #2" icon={TabIcon}>
<Scene
key="tab2_1"
component={TabView}
title="Tab #2_1"
renderRightButton={() => <Right />}
/>
<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" hideTabBar 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;