SubjectPost.js
15.9 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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
'use strict'
import React, {Component} from 'react';
import {
View,
Text,
ListView,
StyleSheet,
Image,
Dimensions,
Keyboard,
TouchableOpacity,
TouchableHighlight,
Animated,
Easing,
Platform,
TextInput,
Alert,
NativeModules,
} from 'react-native'
import UserBrief from '../home/UserBrief';
import PostingService from '../../services/PostingService';
import SPHeaderCell from './SPHeaderCell';
import SubjectContent from './SubjectContent';
import SPLikeCell from './SPLikeCell';
import SPShareGoodsCell from './SPShareGoodsCell';
import SPCommentCell from './SPCommentCell';
import LoadingIndicator from '../../../common/components/LoadingIndicator';
import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator';
import AssertsPicker from '../posting/AssertsPicker';
import SlicedImage from '../../../common/components/SlicedImage';
import SPToolContainerPannel from './SPToolContainerPannel';
let dismissKeyboard = require('dismissKeyboard');
let ReplyState = {
replyNone: 0,
replyLZ: 1,
replySomeone: 2,
}
let {width, height} = Dimensions.get('window');
let navbarHeight = (Platform.OS === 'android') ? 50 : 64;
export default class SubjectPost extends Component {
constructor(props) {
super(props);
this.dataSource = new ListView.DataSource({
rowHasChanged:(r1,r2)=> r1 != r2,
sectionHeaderHasChanged: (s1, s2) => s1 != s2,
});
this.renderRow = this.renderRow.bind(this);
this.state = {
contentInputHeight: new Animated.Value(0),
imageState: 0,
replyState: ReplyState.replyNone,
replyTextColor: '#b0b0b0',
}
this.currentReplyState = ReplyState.replyLZ;
this.boardInView=false;
this.boardHeight=257;
this.boardSelectionHeight = 257;
this.showImagePannel = this.showImagePannel.bind(this);
this.blurAll = this.blurAll.bind(this);
this.renderToolContainer = this.renderToolContainer.bind(this);
this.someOneToReply = '';
this.replyToSomeOneElse = this.replyToSomeOneElse.bind(this);
this.commentId = '';
this.cidTo = '';
this.replyContent='';
this.commitComment = this.commitComment.bind(this);
this.cnameTo = '';
this.onPressComment = this.onPressComment.bind(this);
this.onPressLZContainer = this.onPressLZContainer.bind(this);
this.onReplyTextChange = this.onReplyTextChange.bind(this);
}
componentDidMount(){
this.setState({contentInputHeight: new Animated.Value(height-navbarHeight-0.5),replyState: ReplyState.replyNone});
Keyboard.addListener('keyboardWillChangeFrame',(event)=>{
let kbdHeight = height - event.endCoordinates.screenY;
if (kbdHeight>0) {
this.boardInView = false;
this.setState({imageState: 0});
} else {
if (this.boardInView) {
if (kbdHeight>0) {
this.setState({imageState: 0});
}
return;
}
this.currentReplyState = ReplyState.replyLZ;
this.setState({replyState: ReplyState.replyNone});
}
this.boardHeight = kbdHeight>0?kbdHeight:250;
this.boardSelectionHeight=kbdHeight;
let targetHeight = height-navbarHeight-0.5- kbdHeight;
this.stretchContentInputToHeight(targetHeight, event.duration);
});
}
stretchContentInputToHeight(newHeight, anmDuration) {
Animated.timing(this.state.contentInputHeight, {
toValue: newHeight,
duration:anmDuration,
easing:Easing.keyboard,
}).start();
}
blurAll() {
this.setState({imageState:0, replyState:ReplyState.replyNone});
this.currentReplyState = ReplyState.replyLZ;
if (this.boardInView) {
this.boardInView = false;
let targetHeight = height-navbarHeight-0.5;
this.stretchContentInputToHeight(targetHeight, 250);
}
dismissKeyboard();
}
showImagePannel() {
this.boardInView= true;
this.setState({boardState:0,imageState:this.boardSelectionHeight});
dismissKeyboard();
let targetHeight = height-navbarHeight-0.5- this.boardHeight;
this.stretchContentInputToHeight(targetHeight, 250);
}
render() {
if (this.props.isContentFetching) {
return <LoadingIndicator
isVisible={this.props.isContentFetching}
/>
}
return(
<View style={styles.container}>
<Animated.View
style={[styles.contentInputContainer,{height:this.state.contentInputHeight}]}
>
<ListView
style={styles.container}
dataSource={this.dataSource.cloneWithRowsAndSections(this.props.dataBlob)}
renderRow={this.renderRow}
enableEmptySections={true}
onEndReached={() => {
this.props.onEndReached && this.props.onEndReached();
}}
renderFooter={()=>{
if (!this.props.dataBlob.comments.length) {
return <View style={styles.sofaContainer}>
<Image style={styles.sofaImage} source={require('../../images/posting/ic_null_message.png')}/>
<Text style={styles.sofaText}>快来抢沙发吧~</Text>
</View>
}
if (this.props.endReached) {
return <LoadMoreIndicator
isVisible={true}
text={'暂无更多'}
/>
} else {
return <LoadMoreIndicator
isVisible={true}
animating={this.props.isFetching}
/>
}
}}
/>
{this.renderToolContainer(this.state.replyState)}
</Animated.View>
<AssertsPicker
assets={this.props.assets}
hidden={this.state.imageState == 0}
onSelectedAsset={this.props.assetsSelected}
/>
</View>
);
}
onPressLZContainer() {
this.cidTo = this.props.authorUid;
this.cnameTo = '';
this.commentId = '';
NativeModules.YH_CommunityHelper.uid()
.then(uid => {
new PostingService().getPostUser(uid).then(json => {
if (json.forbidSpeaking === 'Y') {
Alert.alert('抱歉','您暂时被禁言,请等待禁言解除哦~');
} else {
this.setState({replyState: this.currentReplyState});
}
}).catch(error => {
this.setState({replyState: this.currentReplyState});
})
})
.catch(error => {
NativeModules.YH_CommunityHelper.login()
.then(uid => {
new PostingService().getPostUser(uid).then(json => {
if (json.forbidSpeaking === 'Y') {
Alert.alert('抱歉','您暂时被禁言,请等待禁言解除哦~');
} else {
this.setState({replyState: this.currentReplyState});
}
}).catch(error => {
this.setState({replyState: this.currentReplyState});
})
});
});
}
onReplyTextChange(text) {
this.replyContent = text;
if (text.length) {
this.setState({replyTextColor: 'black'});
} else {
this.setState({replyTextColor: '#b0b0b0'});
}
}
renderToolContainer() {
let picSource = (this.state.imageState>0?require('../../images/posting/pic1.png') : require('../../images/posting/pic_normal.png'));
let keboardIcon = (this.state.imageState == 0?require('../../images/posting/jianpan1.png') : require('../../images/posting/keyboard_normal.png'));
let iconSouce = (this.state.replyState === ReplyState.replyNone)?require('../../images/home/like.png'):picSource;
return(
<SPToolContainerPannel
iconSouce={iconSouce}
replyState={this.state.replyState}
likeState={this.props.likeState}
onPressLZContainer={this.onPressLZContainer}
commentCount={this.props.commentCount}
onPressLikeOrDislike={this.props.onPressLikeOrDislike}
blurAll={this.blurAll}
onReplyTextChange={this.onReplyTextChange}
replyTextColor={this.state.replyTextColor}
replyContent={this.replyContent}
showImagePannel={this.showImagePannel}
commitComment={this.commitComment}
someOneToReply={this.someOneToReply}
keboardIcon={keboardIcon}
/>
);
}
commitComment() {
if (this.replyContent.length == 0 && !this.props.assets.length) {
Alert.alert('抱歉','请先输入内容');
return;
}
let params = {
postId: this.props.postId,
commentId: this.commentId,
cidFrom: this.props.cidFrom,
cidTo: this.cidTo,
authorUid: this.props.authorUid,
content: this.replyContent,
}
let blocks = [];
let textBlock = {
"contentData": this.replyContent,
"templateKey": "text",
"orderBy": 1,
};
blocks.push(textBlock);
if (this.props.assets.length) {
for (var i = 0; i < this.props.assets.length; i++) {
let asset = this.props.assets[i];
let imgBlock = {
"contentData": asset.url,
"templateKey": "image",
"size": asset.width + 'x' + asset.height,
};
blocks.push(imgBlock);
}
}
let replyTo;
if (this.cnameTo.length) {
replyTo = {
nickName: this.cnameTo,
uid: this.cidTo,
}
}
let fakeComment = {
blocks,
replyTo,
}
this.props.commentWithParams(params, fakeComment);
this.replyContent = '';
this.blurAll();
}
renderRow(rowData, sectionId) {
switch (sectionId) {
case 'header':
return (
<SPHeaderCell
avatar={rowData.headIcon}
nickName={rowData.nickName}
timeago={rowData.timeago}
isOwner={rowData.LZ}
sectionName={rowData.forumName}
showLZ={true}
onPressAvatar={() => {
this.props.onPressAvatar && this.props.onPressAvatar(rowData.uid);
}}
onPressSection={() => {
this.props.onPressSection && this.props.onPressSection({id: rowData.forumCode, name: rowData.forumName});
}}
onPressReportOrDelete={this.props.onPressReportOrDelete}
/>
);
break;
case 'title':
return(
<Text style={styles.title}>{rowData}</Text>
);
break;
case 'content':
return(
<SubjectContent onPressLargeImage={this.props.onPressLargeImage} blocks={rowData}/>
);
break;
case 'shareGoods':
return (
<SPShareGoodsCell
data={rowData}
onPressShareGoods={this.props.onPressShareGoods}
/>
);
break;
case 'like':
return (
<SPLikeCell
users={rowData.praiseUsers}
like={rowData.praise}
browse={rowData.browse}
onPressLikeCell={() => {
this.props.onPressLikeCell && this.props.onPressLikeCell(rowData.postId, rowData.praise);
}}
/>
);
break;
case 'comments':
return (
<SPCommentCell
data={rowData}
cidFrom={this.props.cidFrom}
LZ={this.props.dataBlob.header[0].LZ}
onPressAvatar={()=>{
this.props.onPressAvatar&&this.props.onPressAvatar(rowData.cidTo);
}}
onPressComment={() => {
this.onPressComment(rowData.cidTo, rowData.nickName, rowData.commentId);
}}
onPressDeleteComment={this.props.onPressDeleteComment}
/>
);
break;
default:
return null;
break;
}
}
onPressComment(cidTo, nickName, commentId) {
this.cidTo = cidTo;
this.cnameTo = nickName;
this.commentId = commentId;
NativeModules.YH_CommunityHelper.uid()
.then(uid => {
new PostingService().getPostUser(uid).then(json => {
if (json.forbidSpeaking === 'Y') {
Alert.alert('抱歉','您暂时被禁言,请等待禁言解除哦~');
} else {
this.replyToSomeOneElse(nickName);
}
}).catch(error => {
this.replyToSomeOneElse(nickName);
})
})
.catch(error => {
NativeModules.YH_CommunityHelper.login()
.then(uid => {
new PostingService().getPostUser(uid).then(json => {
if (json.forbidSpeaking === 'Y') {
Alert.alert('抱歉','您暂时被禁言,请等待禁言解除哦~');
} else {
this.replyToSomeOneElse(nickName);
}
}).catch(error => {
this.replyToSomeOneElse(nickName);
})
});
});
}
replyToSomeOneElse(someOne) {
this.someOneToReply = someOne;
this.currentReplyState = ReplyState.replySomeone;
this.setState({replyState: this.currentReplyState});
}
}
const styles = StyleSheet.create({
container: {
top: 0,
flex: 1,
backgroundColor: 'white',
},
title: {
backgroundColor: 'white',
fontSize: 18,
fontWeight: "100",
lineHeight: 30,
paddingLeft: 15,
paddingRight: 15,
},
sofaContainer: {
flexDirection: 'column',
height: 190,
backgroundColor: 'white',
alignItems: 'center',
},
sofaImage: {
width: 55,
height: 57,
top: 50,
},
sofaText: {
top: 57,
fontSize: 17,
textAlign: 'center',
color: '#b0b0b0',
}
});