TextSingleEditView.js 2.62 KB
import React, {Component} from 'react';
import {
    View,
    Text,
    TextInput,
    Image,
} from 'react-native';
const defaultHeight = (62);
const titleViewHeight = (24);
const HPading = (16);
const VPading = (6);
export default class TextSingleEditView extends Component {

    constructor(props) {
        super(props);
        this.state = {
            inputValue: ''
        }
        this.attrData = this.props.attrData;
        this.onChangeText = this.props.onChangeText;
        this.inputType = this.props.inputType || 'default';
    }

    componentWillMount() {
        if (this.attrData.value && this.attrData.value.length > 0) {
            this.setState({
                inputValue: this.attrData.value
            })
        }
    }

    render() {
        let {name, code, type, description, isRequired, isPreview} = this.attrData;
        let {placeholder, defaultValue, maxLength, minLength} = JSON.parse(this.attrData.data);
        return (
            <View style={{width: '100%', backgroundColor: '#fff', paddingTop: VPading,paddingHorizontal: HPading,height:defaultHeight}}>
                <View style={{flexDirection: 'row',height:titleViewHeight,justifyContent:'flex-start',alignItems:'center'}}>
                    {isRequired&&<Text style={{ color: "#FF3030" }}>* {" "}</Text>}
                    {!isRequired&&<Text style={{ color: "#fff" }}>* {" "}</Text>}
                    <Text style={{fontSize: 16, color: 'rgba(0, 0, 0, 1)'}}>{name||""}</Text>
                </View>
                <TextInput
                    style={{
                        fontSize: 14,
                        color: 'black',
                        flex:1,
                        marginLeft: 14,
                        backgroundColor: '#fff',
                        textAlign: 'left',
                        marginTop:4,
                        marginBottom:4,
                        padding:0
                    }}
                    minLength={minLength}
                    maxLength={maxLength}
                    multiline={false}
                    keyboardType={this.inputType}
                    defaultValue={this.state.inputValue}
                    onChangeText={text => {
                        if (this.onChangeText) {
                            this.onChangeText(text)
                        }
                        this.attrData.value = text;
                    }}
                    placeholderTextColor={'#999'}
                    placeholder={placeholder||'请输入'}
                    value={defaultValue}
                    underlineColorAndroid="transparent"
                />
            </View>
        );
    }
}