SubjectContent.js
3.39 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
'use strict'
import React, {Component} from 'react';
import {
View,
Text,
StyleSheet,
Image,
Dimensions,
TouchableOpacity,
} from 'react-native'
import SlicedImage from '../../../common/components/SlicedImage';
let {width, height} = Dimensions.get('window');
export default class SubjectContent extends Component {
constructor(props) {
super(props);
}
render() {
return(
<View style={[styles.container,{left:this.props.left||0}]}>
{this.props.blocks.map((item,i) => {
let content = item.contentData||'';
if (item.templateKey === 'text') {
if (this.props.replyTo&&this.props.replyTo.nickName&&this.props.replyTo.nickName.length&&this.props.replyTo.uid) {
return(
<Text key={i} style={styles.contentText}>
<Text>回复</Text>
<Text style={{color:'#4a90e2'}} onPress={()=>{this.props.onPressAvatar(this.props.replyTo.uid);}}>{this.props.replyTo.nickName}</Text>
<Text>:{content}</Text>
</Text>
)
}else {
return(
<Text key={i} style={styles.contentText}>{content}</Text>
)
}
} else if (item.templateKey === 'image') {
let imgWidth = this.props.contentWidth||width-30;
let imgHeight = imgWidth;
let sizeStr = item.size || '';
if (sizeStr.length) {
let ary=sizeStr.split('x');
let w = parseInt(ary[0]);
let h = parseInt(ary[1]);
if (w&&h) {
imgHeight = imgWidth/w*h;
}
}
if (this.props.onPressLargeImage) {
return (
<TouchableOpacity
key={i}
style={[styles.contentImage,{width:imgWidth,height:imgHeight}]}
onPress={()=>{
this.props.onPressLargeImage(item.index);
}}
>
<SlicedImage key={i} style={{width:imgWidth,height:imgHeight}} source={{uri:content}}/>
</TouchableOpacity>
);
} else {
return(
<SlicedImage key={i} style={[styles.contentImage,{width:imgWidth,height:imgHeight}]} source={{uri:content}}/>
)
}
}
})}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
padding: 15,
backgroundColor: 'white',
},
contentText: {
fontSize: 14,
lineHeight: 24,
},
contentImage: {
backgroundColor:'#a0a0a0',
width:320,
height: 320,
marginTop: 10,
top: 10,
},
});