Interest.js
6.13 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
'use strict';
import React, {Component} from 'react';
import ReactNative, {
View,
Text,
Image,
StyleSheet,
Dimensions,
TouchableOpacity,
InteractionManager,
Platform,
RefreshControl,
} from 'react-native';
import ListView from 'deprecated-react-native-listview'
import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator';
import LoginTip from './LoginTip';
import InterestCell from './InterestCell';
import InterestActivityCell from './InterestActivityCell';
import Prompt from '../../../coupon/components/coupon/Prompt';
import YH_PtrRefresh from '../../../common/components/YH_PtrRefresh';
export default class Interest extends Component {
constructor(props) {
super(props);
this._renderRow = this._renderRow.bind(this);
this._onEndReached = this._onEndReached.bind(this);
this._renderFooter = this._renderFooter.bind(this);
this.trigggePullToRefresh = this.trigggePullToRefresh.bind(this);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
});
}
componentDidMount() {
this.trigggePullToRefresh();
}
componentWillReceiveProps(nextProps) {
if (nextProps.data.ptr) {
this.listView && this.listView.scrollTo({x: 0, y: 0, animated: false, });
}
}
trigggePullToRefresh() {
if (Platform.OS === 'ios') {
InteractionManager.runAfterInteractions(() => {
this.listView && this.listView.getScrollResponder().startPullToRefresh();
});
} else {
this.props.onRefresh && this.props.onRefresh();
}
}
_renderRow(rowData: object, sectionID: number, rowID: number) {
let type = rowData.get('brand_type', '');
if (type == 'activity') {
return (
<InterestActivityCell
data={rowData}
rowID={rowID}
onInterestLike={this.props.onInterestLike}
onPressBrand={this.props.onPressBrand}
onPressActivity={this.props.onPressActivity}
/>
);
}
return (
<InterestCell
data={rowData}
rowID={rowID}
onInterestLike={this.props.onInterestLike}
onPressBrand={this.props.onPressBrand}
onPressProduct={this.props.onPressProduct}
/>
);
}
_onEndReached() {
let {list} = this.props.data;
if (list.size != 0) {
this.props.onEndReached && this.props.onEndReached();
}
}
_renderFooter() {
let {list, ptr, isFetching, endReached} = this.props.data;
let isPullToRefresh = ptr && isFetching;
let isLoadingMore = list.size != 0 && !ptr && isFetching;
if (endReached) {
return <LoadMoreIndicator
isVisible={true}
text={'暂无更多'}
/>;
} else {
return <LoadMoreIndicator
isVisible={isLoadingMore}
animating={isFetching}
/>;
}
}
render() {
let {list, ptr, isFetching, endReached, showLoginTip, cachedList, addLikeTip} = this.props.data;
let dataSource = list.size == 0 ? cachedList.toArray() : list.toArray();
let isPullToRefresh = ptr && isFetching;
let isLoadingMore = list.size != 0 && !ptr && isFetching;
return (
<View style={styles.container}>
{showLoginTip ? <LoginTip onInterestLogin={this.props.onInterestLogin} /> : null}
{
Platform.OS === 'ios' ? <ListView
ref={(c) => {
this.listView = c;
}}
contentContainerStyle={styles.contentContainer}
dataSource={this.dataSource.cloneWithRows(dataSource)}
renderRow={this._renderRow}
enableEmptySections={true}
enablePullToRefresh={true}
isOnPullToRefresh={isPullToRefresh}
onRefreshData={() => {
this.props.onRefresh && this.props.onRefresh();
}}
yh_viewVisible={true}
onFinishRefreshData={() => {
this.listView && this.listView.yh_updateVisibleSubViews && this.listView.yh_updateVisibleSubViews();//ios 专用
}}//ios 专用
onEndReached={this._onEndReached}
renderFooter={this._renderFooter}
/> : <ListView
ref={(c) => {
this.listView = c;
}}
yh_viewVisible={true}
refreshControl={
<YH_PtrRefresh
refreshing={isPullToRefresh}
onRefresh={() => {
this.props.onRefresh && this.props.onRefresh();
}}
/>
}
contentContainerStyle={styles.contentContainer}
dataSource={this.dataSource.cloneWithRows(dataSource)}
renderRow={this._renderRow}
enableEmptySections={true}
onEndReached={this._onEndReached}
renderFooter={this._renderFooter}
/>
}
{addLikeTip !== '' ? <Prompt
text={'收藏成功'}
duration={800}
onPromptHidden={this.props.interestListTipRemove}
/> : null}
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#f0f0f0',
},
contentContainer: {
},
});