-
Notifications
You must be signed in to change notification settings - Fork 427
/
Copy pathCommonHtmlView.js
109 lines (101 loc) · 4.39 KB
/
CommonHtmlView.js
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
import React, {Component} from 'react';
import {Clipboard, Linking, Image, TouchableWithoutFeedback, Platform, View, ImageBackground} from 'react-native';
import HTMLView from 'react-native-htmlview';
import Toast from './ToastProxy'
import {Actions} from "react-native-router-flux";
import I18n from '../../style/i18n'
import {launchUrl} from '../../utils/htmlUtils'
import styles, {screenWidth} from "../../style/index"
import Icon from 'react-native-vector-icons/Ionicons'
import * as Constant from "../../style/constant";
/**
* 通用横Html解析显示item控件
*/
class CommonHtmlView extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
}
componentWillUnmount() {
}
hadImageChildren(node) {
let hadImageNode = false;
if (node.children && node.children.length > 0) {
for (let i = 0; i < node.children.length; i++) {
let item = node.children[i];
hadImageNode = this.hadImageChildren(item);
if (hadImageNode) {
break;
}
}
}
if (node.type === 'tag' && node.name === 'img') {
return true;
} else {
return hadImageNode;
}
}
render() {
return (
<HTMLView
onLinkPress={(link) => {
if (link && (link.indexOf("http") === 0 || link.indexOf("www") === 0)) {
launchUrl(link);
} else {
Linking.openURL(link)
}
}}
selectable={true}
onLinkLongPress={(link) => {
Clipboard.setString(link);
Toast(I18n("hadCopy"));
}}
renderNode={
(node, index, list, parent, domToElement) => {
if (node.type === 'tag') {
if (node.name === 'img') {
return (
<TouchableWithoutFeedback
key={index}
onPress={() => {
Actions.PhotoPage({uri: node.attribs.src})
}}>
<View style={{
width: screenWidth - 105,
height: 300
}}>
<View style={[styles.centered, styles.absoluteFull, {
zIndex: -888,
width: screenWidth - 105,
height: 300,
}]}>
<Icon name={'ios-image'} size={80} color={Constant.miWhite}/>
</View>
<Image source={{uri: node.attribs.src}}
resizeMethod="scale"
style={[styles.centerH, {
width: screenWidth - 105,
height: 300,
marginTop: 5
}]}>
</Image>
</View>
</TouchableWithoutFeedback>
)
} else {
let img = this.hadImageChildren(node);
if (img) {
return <View key={index}>
{domToElement(node.children, node)}
</View>
}
}
}
}
}
{...this.props}/>
)
}
}
export default CommonHtmlView