-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ios.js
215 lines (199 loc) · 5.36 KB
/
index.ios.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
215
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Navigator,
NavigatorIOS,
TouchableOpacity,
Platform
} from 'react-native';
//var TimerMixin = require('react-timer-mixin');
import SplashScreen from './SplashScreen';
import MainScreen from './MainScreen';
import StoryScreen from './StoryScreen';
import Icon from 'react-native-vector-icons/Ionicons';
var _navigator;
class DotaClub extends Component {
constructor(props) {
super(props);
this.state = {
splashed: false,
hideNavBar: false,
};
this._willFocus = this._willFocus.bind(this);
this.RightButton = this.RightButton.bind(this);
}
componentDidMount() {
setTimeout(
() => {
this.setState({splashed: true});
},
2000
);
}
RouteMapper(route, navigationOperations, onComponentRef) {
_navigator = navigationOperations;
// return (
// <View style={styles.container}>
// <MainScreen navigator={navigationOperations}/>
// </View>
// );
if (route.name === 'home') {
return (
<View style={styles.container}>
<MainScreen navigator={navigationOperations}/>
</View>
);
} else if (route.name === 'story') {
return (
<View style={styles.container}>
<StoryScreen
style={{flex: 1}}
navigator={navigationOperations}
story={route.story} />
</View>
);
}
}
// Nav使用
navBar() {
if(!this.state.hideNavBar) {
return <Navigator.NavigationBar
routeMapper={{
LeftButton: this.LeftButton,
RightButton: this.RightButton,
Title: this.Title
}}
style={styles.navBar}
/>;
} else {
return <Text style={{height:0,position:'absolute',top:0}} />;
}
}
LeftButton(route, navigator, index, navState) {
return (
<TouchableOpacity
onPress={() => navigator.pop()}
style={styles.navBarLeftButton}>
<Icon
name='ios-arrow-dropleft'
size={30}
color='#666'
style={styles.icon}
/>
</TouchableOpacity>
);
}
RightButton(route, navigator, index, navState) {
if(route.isStar) {
return (
<TouchableOpacity
onPress={()=>this._changeDetailStar(route,navigator,this.state.starDatas)}
style={styles.navBarRightButton}>
<Icon
name='ios-star'
size={30}
color='#333'
style={styles.icon}
/>
</TouchableOpacity>
);
} else {
return (
<TouchableOpacity
onPress={()=>this._changeDetailStar(route,navigator,this.state.starDatas)}
style={styles.navBarRightButton}>
<Icon
name='ios-star-outline'
size={30}
color='#333'
style={styles.icon}
/>
</TouchableOpacity>
);
}
}
_changeDetailStar(route,navigator) {
}
Title(route, navigator, index, navState) {
return null;
}
// 监听的回调
_willFocus(route) {
if(route.sence == 'detail') {
// 这里写逻辑来加载收藏的路由
this.setState({
hideNavBar:false,
});
} else {
this.setState({
hideNavBar:true,
});
}
}
render() {
if (this.state.splashed) {
var initialRoute = {name: 'home'};
return (
// <NavigatorIOS
// style={styles.container}
// initialRoute={{
// title: '首页',
// component: MainScreen,
// }}
// />
<Navigator
style={styles.container}
initialRoute={initialRoute}
configureScene={() => Navigator.SceneConfigs.FadeAndroid}
renderScene={this.RouteMapper}
navigationBar={this.navBar()}
onWillFocus={this._willFocus}
/>
);
// return (
// <View style={styles.container}>
// <MainScreen />
// </View>
// );
} else {
return (
<SplashScreen />
);
}
}
};
var styles = StyleSheet.create({
container: {
flex: 1,
},
navBar: {
backgroundColor:'#fff',
borderColor:'#dddddd',
borderWidth:1,
height: (Platform.OS === 'ios')? 64: 48
},
navBarTitleText: {
fontWeight: '500',
},
navBarLeftButton: {
paddingLeft: 5,
},
navBarRightButton: {
marginRight:5,
},
icon: {
width:30,
height:30,
marginTop:(Platform.OS === 'ios')? 6: 9,
textAlign:'center'
}
});
AppRegistry.registerComponent('DotaClub', () => DotaClub);