LabelLinkView.js
2.45 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
import React, {Component} from 'react';
import {Text, TouchableOpacity} from 'react-native';
// 默认高度
const defaultHeight = (30);
// 默认垂直内边距
const VPading = (6);
/*
提示文字组件(type:'LABEL')
*/
export default class LabelLinkView extends Component {
// 构造方法
constructor(props) {
super(props);
this.state = {}
// 传入参数
this.attrData = this.props.attrData;
// json解析后的传入参数
this.extendData = (this.attrData.data && this.attrData.data.length > 0) ? JSON.parse(this.attrData.data) : {};
}
// 绘制UI
render() {
/*
name:标题
code:代码编号
type:控件类型(LABEL)
description:描述
isRequired:是否必须
isPreview:是否预览
*/
let {name, code, type, description, isRequired, isPreview} = this.attrData;
/*
placeholder:提示文字
hyperlink:超链接
*/
let {placeholder, hyperlink} = this.extendData;
// 是否为超链接
let isHyperlink = !!hyperlink && hyperlink.length > 0 && (hyperlink.indexOf('http://') === 0 || hyperlink.indexOf('https://') === 0);
return (
// 最外层点击触发区域(可以触发超链接跳转)
<TouchableOpacity
style={{
width: '100%',
backgroundColor: 'rgba(245, 245, 245, 1)',
flexDirection: 'row',
alignItems: 'center',
paddingVertical: VPading,
paddingLeft: 10,
paddingRight: 15,
minHeight: defaultHeight
}}
activeOpacity={0.8}
onPress={() => {
if (isHyperlink) {
this.props.navigation.navigate("CommonWebView", {url: hyperlink})
}
}}
>
{/*{isRequired&&<Text style={{ color: "#FF3030" }}>* {" "}</Text>}*/}
{/*{!isRequired&&<Text style={{ color: "#fff" }}>* {" "}</Text>}*/}
{/*显示文字*/}
<Text style={{
fontSize: 14,
color: '#999',
marginLeft: 10,
textDecorationLine: isHyperlink ? 'underline' : 'none'
}}>{placeholder || description}</Text>
</TouchableOpacity>
);
}
}