Detail.js
15.5 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
'use strict';
import React, {Component} from 'react';
import Immutable, {Map} from 'immutable';
import DetailBrand from './DetailBrand';
import OtherArticle from './OtherArticle';
import Tags from './Tags';
import SingleImage from './SingleImage';
import DetailText from './DetailText';
import GoodsCell from './GoodsCell';
import Header from './Header';
import MoreLink from './MoreLink';
import GoodsGroupHeader from './GoodsGroupHeader';
import GoodsGroupList from './GoodsGroupList';
import SmallPic from './SmallPic';
import Weixin from './Weixin';
import WeChatPublic from './WeChatPublic';
import LoadingIndicator from '../../../common/components/LoadingIndicator';
import RecommentProducts from './RecommentProducts';
import Comments from './Comments';
import CommentsTitle from './CommentsTitle';
import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator';
import YH_Video from '../../../common/components/YH_Video';
import DeviceInfo from 'react-native-device-info';
import ReactNative, {
View,
Text,
Image,
ListView,
StyleSheet,
Dimensions,
TouchableOpacity,
InteractionManager,
Platform,
TextInput,
Animated,
Keyboard,
} from 'react-native';
export default class Detail extends Component {
constructor(props) {
super(props);
this.renderRow = this.renderRow.bind(this);
this.renderHeader = this.renderHeader.bind(this);
this.scrollTo = this.scrollTo.bind(this);
this._onPressComment = this._onPressComment.bind(this);
this._onSubmitEditing = this._onSubmitEditing.bind(this);
this.listView = null;
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
});
this.state = {
viewMarginTop : new Animated.Value(0),
replyTo: 0,
relayToUsername: '',
};
}
componentWillUnmount() {
this.keyboardDidShowListener.remove();
this.keyboardDidHideListener.remove();
}
componentWillMount() {
this.keyboardDidShowListener = Keyboard.addListener('keyboardWillShow', this._keyboardWillShow.bind(this));
this.keyboardDidHideListener = Keyboard.addListener('keyboardWillHide', this._keyboardWillHide.bind(this));
}
onLayout(rowID, e) {
let {y} = e.nativeEvent.layout;
this.props.onPressGoodY(y);
}
scrollTo(){
let {goods_group_y} = this.props.resource;
this.listView.scrollTo({x: 0, y: goods_group_y, animated: false});
}
_keyboardWillShow(e){
let endH = e.endCoordinates.height;
let duration = e.duration;
if (deviceId == 'iPhone10,3' || deviceId == 'iPhone10,6')
{
endH = endH - 34;
}
Animated.timing(
this.state.viewMarginTop,
{
toValue: -endH,
duration: duration,
}
).start();
}
_keyboardWillHide(e){
let duration = e.duration;
Animated.timing(
this.state.viewMarginTop,
{
toValue: 0,
duration: duration,
}
).start();
}
_onSubmitEditing(event){
let content = event.nativeEvent.text;
let replyTos = this.state.replyTo;
let relayToUsername = this.state.relayToUsername;
if (this.state.replyTo == 0) {
replyTos = '';
relayToUsername = '';
}
this.props.onSubmitForComment && this.props.onSubmitForComment(content,replyTos);
this.refs.textInput.clear();
if (Platform.OS === 'ios') {
this.refs.textInput.setNativeProps({ text: ' ' });
setTimeout(() => {
this.refs.textInput.setNativeProps({ text: '' });
});
}
this.setState({replyTo: 0,relayToUsername: ''});
}
_onPressComment(id,username){
this.setState({replyTo: id,relayToUsername: username});
this.refs.textInput && this.refs.textInput.focus();
}
renderHeader() {
let {resource} = this.props;
let {author,article} = resource;
return(
<Header resource={{author,article}} onPressAuthor={this.props.onPressAuthor} />
);
}
renderRow(rowData,sectionID,rowID,highlightRow) {
if (sectionID == 'detailList') {
let template_name = rowData.get('template_name');
if (template_name == 'text') {
return (
<DetailText resource={rowData} onPressLink={this.props.onPressLink}/>
);
}else if (template_name == 'single_image') {
return (
<SingleImage resource={rowData} onPressLink={this.props.onPressLink} onPressShopCar={this.props.onPressShopCar} onPressProduct={this.props.onPressTagProduct}/>
);
}else if (template_name == 'video') {
let data = rowData?rowData.get('data'):null;
let url = data?data.get('src'):'';
let title = data?data.get('video_intro'):'';
let cover_image = data?data.get('cover_image'):'';
let articleId = this.props.resource.articleId;
return (
<View style={styles.videoView}>
<YH_Video style={styles.video} articleId={articleId} url={url} title={title} cover={cover_image} />
<View style={styles.placeholder}/>
</View>
);
}else if (template_name == 'small_pic') {
return (
<SmallPic resource={rowData}/>
);
}else if (template_name == 'goods_group') {
let {resource} = this.props;
let {goods_group_Filter} = resource;
let data = rowData.get('productList')?rowData.get('productList').toArray():null;
let list = data?data[goods_group_Filter]:null;
return (
<View style={styles.GoodsGroupHeader} onLayout={this.onLayout.bind(this, rowID)}>
<GoodsGroupHeader resource={rowData} goods_group_Filter={goods_group_Filter} onPressFilter= {this.props.onPressFilter} scrollTo={this.scrollTo}/>
<GoodsGroupList resource={list} onPressProduct={this.props.onPressProduct}/>
</View>
);
}else if (template_name == 'goods') {
let {resource} = this.props;
let {
articleId,
} = resource;
return (
<GoodsCell resource={rowData} articleId={articleId} onPressProduct={this.props.onPressProduct} onPressShopCar={this.props.onPressShopCar}/>
);
}else if (template_name == 'link') {
return (
<MoreLink resource={rowData} onPressMoreLink={this.props.onPressMoreLink}/>
);
}else if (template_name == 'recommend_products') {
return (
<RecommentProducts resource={rowData} onPressProduct={this.props.onPressProduct}/>
);
}
}else if (sectionID == 'weixin') {
return (
<Weixin resource={rowData} onPressWeixin={this.props.onPressWeixin}/>
);
}else if (sectionID == 'detailBrand') {
return (
<DetailBrand resource={rowData} onPressBrand={this.props.onPressBrand}/>
);
}else if (sectionID == 'detailOtherArticle') {
return (
<OtherArticle resource={rowData} onPressArticle={this.props.onPressArticle}/>
);
} else if (sectionID == 'tags'){
return (
<Tags resource={rowData} onPressTag={this.props.onPressTag}/>
);
} else if (sectionID == 'weChatPublic'){
return (
<WeChatPublic resource={rowData} onPressWeixin={this.props.onPressWeixin}/>
);
} else if (sectionID == 'commentsTitle'){
let {resource} = this.props;
let {commentsList} = resource;
let total = commentsList?commentsList.get('total'):0;
return (
<CommentsTitle resource={rowData} total={total}/>
);
}else if (sectionID == 'comments'){
return (
<Comments resource={rowData} onThumbsUp={this.props.addPraiseForComments} onPressComment={this._onPressComment}/>
);
}else if (sectionID == 'space'){
return (
<View style={{width: width,height: 20,backgroundColor: 'white',}}/>
);
}
return (<View style={{height:1,width:width,backgroundColor:'white'}}/>);
}
render() {
let {resource} = this.props;
let {
articleId,
article,
author,
content,
brand,
otherArticle,
weixin,
goods_group_Filter,
wechat,
commentsList,
addComment,
addPraiseInfo,
} = resource;
let list = content?content.get('data'):null;
let comments = commentsList?commentsList.get('data'):null;
let dataSource = {
detailList: list&&list.size>0?list.toArray():[],
weixin: [weixin],
detailBrand: [brand],
detailOtherArticle: [otherArticle],
tags:[article],
weChatPublic: [wechat],
commentsTitle: [addPraiseInfo],
comments: comments&&comments.size>0?comments.toArray():[],
space: ['1'],
};
let isFetching = content.isFetching || article.isFetching || author.isFetching;
let isFavor = addPraiseInfo.get('isFavor')?addPraiseInfo.get('isFavor'):'N';
let isPraise = addPraiseInfo.get('isPraise')?addPraiseInfo.get('isPraise'):'N';
let isFavorIcon = isFavor=='Y' ? require('../../image/g_x_ic_h.png') : require('../../image/g_x_ic.png');
let isPraiseIcon = isPraise=='Y' ? require('../../image/g_z_ic_h.png') : require('../../image/g_z_ic.png');
let praiseNum = addPraiseInfo.get('praiseNum')?addPraiseInfo.get('praiseNum'):0;
let praiseNumText = praiseNum > 999 ? ' 999+' : ' '+praiseNum+' ';
let comlist = commentsList?commentsList.toJS():null;
let isLoadingMore = comlist && comlist.isFetching && comlist.page > 0;
let endReached = comlist ? comlist.endReached : false;
return (
<View style={styles.container}>
{!isFetching?<Animated.View style={{flex: 1,top:this.state.viewMarginTop}}>
<ListView
ref={(ref)=>this.listView=ref}
yh_viewVisible = {true}//自动曝光开关
initialListSize={1}
contentContainerStyle={styles.contentContainer}
enableEmptySections={true}
showsVerticalScrollIndicator={false}
dataSource={this.dataSource.cloneWithRowsAndSections(dataSource)}
renderRow={this.renderRow}
renderHeader={this.renderHeader}
keyboardDismissMode={'on-drag'}
renderFooter={()=>{
if (endReached) {
return <View style={styles.placeholder} />;
} else {
return <LoadMoreIndicator
isVisible={isLoadingMore}
animating={true}
/>;
}
}}
onEndReached={() => {
if (comlist && comlist.data && comlist.data.length > 0) {
this.props.onEndReached && this.props.onEndReached();
}
}}
/>
<View style={{width: width,height: 1,backgroundColor: '#e5e5e5',}}/>
<View style={styles.commtentBottomView}>
<TextInput
style={styles.inputStyle}
placeholder = {this.state.relayToUsername == '' ? '赶紧参与评论吧~' : '回复:' + this.state.relayToUsername}
returnKeyType = 'send'
enablesReturnKeyAutomatically = {true}
onSubmitEditing = {this._onSubmitEditing}
clearButtonMode = 'while-editing'
underlineColorAndroid = "transparent"
ref = 'textInput'/>
<TouchableOpacity onPress={()=>{
this.props.onPressConcerns&&this.props.onPressConcerns(isFavor=='Y'?'N':'Y')}
}>
<Image style={styles.favIcon} source={isFavorIcon}/>
</TouchableOpacity>
<TouchableOpacity onPress={()=>{this.props.addPraiseForArtivle&&this.props.addPraiseForArtivle(isPraise=='Y'?'N':'Y')}}>
<View style={styles.thumbsUpView}>
<Image style={styles.thumbsUpIcon} source={isPraiseIcon}/>
{praiseNum > 0 ? <View style={styles.thumbsUpNumView}>
<Text style={styles.thumbsUpNumText}>{praiseNumText}</Text>
</View> : null}
</View>
</TouchableOpacity>
</View>
</Animated.View>
:<LoadingIndicator
isVisible={isFetching}
/>}
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let deviceId = DeviceInfo.getDeviceId();
let styles = StyleSheet.create({
container: {
flex: 1,
},
contentContainer:{
backgroundColor: 'white',
},
GoodsGroupHeader: {
flex: 1,
},
commtentBottomView: {
width: width,
height: 60,
backgroundColor: 'white',
flexDirection: 'row',
alignItems: 'center',
},
inputStyle: {
backgroundColor: '#e0e0e0',
width: width - 120,
height: 40,
marginLeft: 10,
marginTop: 10,
marginBottom: 10,
borderRadius: 5,
padding: 5,
},
favIcon: {
height: 20,
width: Math.ceil(20 * (17/16)),
marginLeft: 25,
},
thumbsUpView: {
height: 50,
width: 40,
marginLeft: 20,
justifyContent: 'center',
backgroundColor: 'white',
},
thumbsUpIcon: {
height: 20,
width: 20,
},
videoView: {
width: width - 20,
height: Math.ceil((width-20)*(430/730)) + 15,
backgroundColor: 'white',
marginLeft: 10,
},
video: {
width: width - 20,
height: Math.ceil((width-20)*(430/730)),
backgroundColor: 'white',
},
placeholder: {
width,
height: 15,
},
thumbsUpNumView: {
backgroundColor: 'red',
borderRadius: 5,
position: 'absolute',
left: 12,
top: 10,
},
thumbsUpNumText: {
backgroundColor: 'transparent',
fontSize: 10,
color: 'white',
},
});