ItemWebView.js
2.93 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
import React, {Component} from "react";
import {StyleSheet, View} from "react-native";
import {zoomH, zoomW} from "../../utils/getSize";
import MyWebView from "react-native-webview-autoheight";
import RichText from "../../widget/RichText";
//图片资源
const defaultIcon = require('../../img/defaultIcon.png');
/**
* 文章类型 item
*
* 调用者需要传入的参数数据源示例(字段必须要保持一致):{
* isForward: false,//是否是转发
* forwardContent:'转发了',//转发填写的内容,不是转发填'',
* threadDetailContent:'xxxxx',//原帖子的详细内容,富文本样式
* }
*/
export default class ItemWebView extends Component {
//自定义属性默认值
static defaultProps = {
data:{},//数据源
nav:{},//导航跳转
};
// 构造
constructor(props) {
super(props);
console.log(111);
let forwardContent;
let threadDetailContent;
if (this.props.data.forwardContent){
forwardContent = this.props.data.forwardContent.replace(/\<img/g,'<img width=100% height="auto"');
}
if (this.props.data.threadDetailContent) {
threadDetailContent = this.props.data.threadDetailContent.replace(/\<img/g,'<img width=100% height="auto"')
}
this.state = {
forwardContent:forwardContent?forwardContent:this.props.data.forwardContent,
threadDetailContent:threadDetailContent?threadDetailContent:this.props.data.threadDetailContent
}
}
render() {
return (
<View>
{/*转发*/}
{!!this.props.data.isForward && (
<View style={{ width: "100%", marginLeft: 15 / zoomW,marginRight:15/zoomW,marginTop:8/zoomH,marginBottom:8/zoomH }}>
<RichText
item={this.state.forwardContent}
nav={this.props.nav}
clearNumberOfLine ={true}
/>
</View>
)}
<View
style={
!!this.props.data.isForward
? styles.forwardingBg
: styles.commonBg
}
>
{this.state.threadDetailContent && <MyWebView
style= {{width:'100%'}}
source={{html:this.state.threadDetailContent}}
startInLoadingState={true}
/>}
</View>
</View>
)
}
}
const styles = StyleSheet.create({
forwardingBg: {
marginLeft:15/zoomW,
marginRight:15/zoomW,
paddingTop:14/zoomH,
borderWidth: 1,
borderColor: "#eeeeee"
},
commonBg: {
},
});