LabelLinkView.js 1.8 KB
import React, {Component} from 'react';
import {
    View,
    Text,
    TouchableOpacity
} from 'react-native';
const defaultHeight = (30);
const VPading = (6);
export default class LabelLinkView extends Component {

    constructor(props) {
        super(props);
        this.state = {}

        this.attrData = this.props.attrData;
        this.extendData = (this.attrData.data && this.attrData.data.length > 0)?JSON.parse(this.attrData.data):{};
    }

    render() {
        let {name, code, type, uom, description, isRequired, isPreview} = this.attrData;
        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,
                    height: 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}</Text>
            </TouchableOpacity>
        );
    }
}