forked from race604/ZhiHuDaily-React-Native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetailToolbar.js
164 lines (155 loc) · 4.2 KB
/
DetailToolbar.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
'use strict';
var React = require('react-native');
var Icon = require('react-native-vector-icons/Ionicons');
var {
AppRegistry,
Platform,
PixelRatio,
StyleSheet,
Text,
View,
Image,
TouchableNativeFeedback,
TouchableHighlight,
ToastAndroid,
} = React;
var SwitchAndroid = require('SwitchAndroid');
var ToolbarAndroid = require('ToolbarAndroid');
var statusBarSize = Platform.OS == 'ios' ? 10 : 0;
var API_STROY_EXTRA = 'http://news-at.zhihu.com/api/4/story-extra/';
var DetailToolbar = React.createClass({
getInitialState: function() {
return({
isLoading: true,
extra: null,
});
},
componentDidMount: function() {
this.fetchStroyExtra();
},
fetchStroyExtra: function() {
fetch(API_STROY_EXTRA + this.props.story.id)
.then((response) => response.json())
.then((responseData) => {
this.setState({
isLoading: false,
extra: responseData,
});
})
.catch((error) => {
this.setState({
isLoading: false,
extra: null,
});
})
.done();
},
_onPressBackButton: function() {
if (this.props.navigator) {
this.props.navigator.pop();
}
},
_onPressShareButton: function() {
// TODO:
ToastAndroid.show('分享', ToastAndroid.SHORT);
},
_onPressCollectButton: function() {
// TODO:
ToastAndroid.show('收藏', ToastAndroid.SHORT);
},
_onPressCommentButton: function() {
// TODO:
ToastAndroid.show('评论', ToastAndroid.SHORT);
},
_onPressPriseButton: function() {
// TODO:
ToastAndroid.show('赞', ToastAndroid.SHORT);
},
render: function() {
var TouchableElement = TouchableHighlight;
if (Platform.OS === 'android') {
TouchableElement = TouchableNativeFeedback;
}
return(
<View {...this.props}>
<View style={styles.actionsContainer}>
<TouchableElement onPress={this._onPressBackButton}>
<View style={styles.actionItem}>
<Icon name='ios-arrow-back' size={30} color="#FFF" />
</View>
</TouchableElement>
<View style={{flex: 1}} />
<TouchableElement onPress={this._onPressShareButton}>
<View style={styles.actionItem}>
<Icon name='share' size={30} color="#FFF" />
</View>
</TouchableElement>
<TouchableElement onPress={this._onPressCollectButton}>
<View style={styles.actionItem}>
<Icon name='ios-star' size={30} color="#FFF" />
</View>
</TouchableElement>
<TouchableElement onPress={this._onPressCommentButton}>
<View style={styles.actionItem}>
<Icon name='chatbox-working' size={25} color="#FFF" />
<Text style={styles.count}>
{(this.state.isLoading || !this.state.extra) ? '...' : ' ' + this.state.extra.comments}
</Text>
</View>
</TouchableElement>
<TouchableElement onPress={this._onPressPraiseButton}>
<View style={styles.actionItem}>
<Icon name='ios-heart' size={25} color="#FFF" />
<Text style={styles.count}>
{(this.state.isLoading || !this.state.extra) ? '...' : ' ' + this.state.extra.popularity}
</Text>
</View>
</TouchableElement>
</View>
</View>
// <ToolbarAndroid
// navIcon={require('image!ic_back_white')}
// onIconClicked={this.props.navigator.pop}
// titleColor="white"
// actions={[]} >
// </ToolbarAndroid>
);
},
});
var styles = StyleSheet.create({
actionsContainer: {
height: 56,
paddingTop: statusBarSize,
flexDirection: 'row',
alignItems: 'center',
},
backIcon: {
width: 32,
height: 32,
marginLeft: 8,
marginRight: 8,
},
actionItem: {
height: 56,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
paddingLeft: 8,
paddingRight: 8,
},
actionIcon: {
width: 32,
height: 32,
},
actionIconWithCount: {
width: 32,
height: 32,
marginLeft: 5,
},
count: {
fontSize: 16,
color: 'white',
marginRight: 5,
},
});
module.exports = DetailToolbar;