-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ios.js
158 lines (137 loc) · 3.57 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var DataWarehouse = require('./DataWarehouse');
var MainScreen = require('./MainScreen');
var {
AppRegistry,
StyleSheet,
Navigator,
Text,
Image,
Animated,
Dimensions,
View,
StatusBar,
NavigatorIOS,
} = React;
let requestUrl = DataWarehouse.cover;
let WINDOW_WIDTH = Dimensions.get('window').width;
var ZhihuDaily = React.createClass({
getInitialState: function(){//ES6 风格
return {
cover: null,
bounceValue: new Animated.Value(1),
splashed: false //表示没有显示过splash image
};
},
componentDidMount: function(){
this._fetchCoverImg();
this.state.bounceValue.setValue(1); // Start large
Animated.timing(
this.state.bounceValue,
{
toValue: 1.2,
duration: 5000,
}
).start();
},
_fetchCoverImg: function(){
fetch(requestUrl)
.then(response => response.json())
.then(response => this._handleImg(response));//setState之后会自动调用render函数
},
_handleImg: function(response){
console.log(response);
this.setState({
cover: {
url: response.img,
text: response.text
}
});
//定时器,定时2秒进入listView
setTimeout(()=>{
this.setState({
splashed: true
});
},1000)
},
_renderScreen: function(route,navigator){
return (
<View style={styles.container}>
<MainScreen navigator={navigator}/>
</View>
);
},
render: function(){
var source,text;
console.log("state="+this.state);
if(this.state.cover){
source = {uri:this.state.cover.url};
text = this.state.cover.text;
} else {
source = require('./img/splash.png');
text = '';
}
if(this.state.splashed){
return (
<Navigator
initialRoute={{name: 'MainScreen', component: MainScreen}}
configureScene={() => {
return Navigator.SceneConfigs.FloatFromRight;
}}
renderScene={(route, navigator) => {
/*
* navigator的使用方法
* http://stackoverflow.com/questions/29335523/react-native-custom-navigation-with-navigator-component
* 但是又有点不同,必须这样,否则后面navigator传不了props
* https://github.com/facebook/react-native/issues/1103
*
*/
if (route.component) {
var Component = route.component;
return (<View style={{flex: 1}}>
<Component navigator={navigator} route={route} {...route.passProps}/>
</View>);
}
}}
/>);
} else {
return (
<View style={styles.container}>
<Animated.Image
source = {source}
style={{
flex: 1,
width: WINDOW_WIDTH,
height: 1,
transform: [
{scale: this.state.bounceValue},
],
}}
/>
<Image source={require('./img/splash_logo.png')} style={styles.logo}/>
</View>
);
}
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
},
logo: {
resizeMode: 'contain',
position: 'absolute',
bottom: 30,
width: 54,
left: 150,
right: 0,
backgroundColor: 'transparent'
}
});
AppRegistry.registerComponent('ZhihuDaily', () => ZhihuDaily);