UserThatNotMe.js
7.42 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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import ScrollableTabView from 'react-native-scrollable-tab-view';
import ImmutablePropTypes from 'react-immutable-proptypes';
import UserCenterTop from '../user/UserCenterTop';
import ListCell from '../home/ListCell';
import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator';
import UserNavBar from '../user/UserNavBar';
const {
View,
Text,
ListView,
Platform,
Dimensions,
StyleSheet,
Animated,
} = ReactNative;
export default class UserThatNotMe extends React.Component {
static propTypes = {
user: ImmutablePropTypes.contains({
avatar: React.PropTypes.string,
backgroundImage: React.PropTypes.string,
nickName: React.PropTypes.string.isRequired,
sign: React.PropTypes.string,
}),
posts: ImmutablePropTypes.listOf(
ImmutablePropTypes.contains({
author: ImmutablePropTypes.contains({
avatar: React.PropTypes.string,
uid: React.PropTypes.number,
name: React.PropTypes.string,
}),
timeago: React.PropTypes.string.isRequired,
isOwner: React.PropTypes.bool,
isTop: React.PropTypes.bool,
isLike: React.PropTypes.bool,
id: React.PropTypes.number,
title: React.PropTypes.string,
desc: React.PropTypes.string,
thumbs: ImmutablePropTypes.listOf(
ImmutablePropTypes.contains({
src: React.PropTypes.string,
})
),
section: ImmutablePropTypes.contains({
id: React.PropTypes.number,
name: React.PropTypes.string,
}),
commentCount: React.PropTypes.number,
likeCount: React.PropTypes.number,
}),
),
onPressPost: React.PropTypes.func,
onPressAvatar: React.PropTypes.func,
onPressSectionTag: React.PropTypes.func,
onPressComment: React.PropTypes.func,
onPressLike: React.PropTypes.func,
onEndReached: React.PropTypes.func,
};
constructor(props) {
super (props);
this._renderHeader = this._renderHeader.bind(this);
this._renderRow = this._renderRow.bind(this);
this._renderSectionHeader = this._renderSectionHeader.bind(this);
this._renderSeparator = this._renderSeparator.bind(this);
this._updateScrollValue = this._updateScrollValue.bind(this);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
});
this.state = {
scrollValue: new Animated.Value(0),
};
}
componentDidMount() {
}
_renderHeader() {
return (
<UserCenterTop
userInfo={this.props.user}
/>
);
}
_renderSectionHeader(sectionData, sectionID) {
switch (sectionID) {
case 'posts':
return (
<View style={styles.sectionHeader}>
<Text style={styles.sectionHeaderText}>TA的发布</Text>
<View style={styles.sectionHeaderLine}/>
</View>
);
default:
return null;
}
}
_renderSeparator(sectionID, rowID, adjacentRowHighlighted) {
return (
<View key={'separator' + sectionID + rowID} style={styles.separator}/>
);
}
_renderRow(rowData, sectionID, rowID, highlightRow) {
switch (sectionID) {
case 'posts':
return (
<ListCell
key={sectionID + rowID}
data={rowData}
onPressPost={() => {
this.props.onPressPost && this.props.onPressPost(rowData.get('id'));
}}
onPressAvatar={() => {
this.props.onPressAvatar && this.props.onPressAvatar(rowData.get('author').get('uid'));
}}
onPressSectionTag={() => {
this.props.onPressSectionTag && this.props.onPressSectionTag(rowData.get('section').toJS());
}}
onPressComment={() => {
this.props.onPressComment && this.props.onPressComment(rowData.get('id'));
}}
onPressLike={() => {
this.props.onPressLike && this.props.onPressLike(rowData);
}}
/>
);
default:
return null;
}
}
_updateScrollValue(value) {
this.state.scrollValue.setValue(value);
}
render() {
let {posts, endReached, isRefreshing, isLoadingMore, isFetching} = this.props;
let dataSource = {
posts: posts.toArray(),
}
return (
<View style={styles.container}>
<ListView
ref={(c) => {
this.listView = c;
}}
onScroll={(e) => {
const offsetY = e.nativeEvent.contentOffset.y;
this._updateScrollValue(offsetY / 150);
}}
dataSource={this.dataSource.cloneWithRowsAndSections(dataSource)}
renderHeader={this._renderHeader}
renderRow={this._renderRow}
renderSectionHeader={this._renderSectionHeader}
renderSeparator={this._renderSeparator}
enableEmptySections={true}
enablePullToRefresh={false}
onEndReached={() => {
this.props.onEndReached && this.props.onEndReached();
}}
renderFooter={()=>{
if (endReached) {
return <LoadMoreIndicator
isVisible={true}
text={'没有更多啦'}
/>
} else {
return <LoadMoreIndicator
isVisible={isLoadingMore}
animating={isFetching}
/>
}
}}
/>
<UserNavBar scrollValue={this.state.scrollValue} channel={this.props.channel}/>
</View>
)
}
}
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
container: {
flex: 1,
},
sectionHeader: {
flexDirection: 'row',
height: 46,
alignItems: 'center',
backgroundColor: 'white',
borderTopWidth: 0.5,
borderTopColor: '#e0e0e0',
},
sectionHeaderText: {
fontSize: 18,
marginLeft: 17,
fontFamily: 'Helvetica Light',
},
sectionHeaderLine: {
position: 'absolute',
left: 17,
bottom: 0,
width: width,
height: 0.5,
backgroundColor: '#e0e0e0',
},
separator: {
height: 0.5,
backgroundColor: '#e0e0e0',
},
});