SliderView.js 2.02 KB
import React, {Component} from 'react';
import {
    View,
    Text,
    Slider
} from 'react-native';

export default class SliderView extends Component {

    constructor(props) {
        super(props);
        this.state = {
            sliderValue: 0,
        };
        this.attrData = this.props.attrData;
        this.onComplete = this.props.onComplete;
    }

    render() {
        let {name, code, type, description, isRequired, isPreview} = this.attrData;
        let extendData = JSON.parse(this.attrData.data);
        let {step, minValue, maxValue, showSpaceDot, rangeSlide} = extendData;
        let defaultValue = extendData.default;
        return(
            <View style={{width: '100%', backgroundColor: 'white', paddingHorizontal: 5, paddingVertical: 10}}>
                <View style={{flexDirection: 'row'}}>
                    {isRequired&&<Text style={{ color: "#FF3030" }}>* {" "}</Text>}
                    {!isRequired&&<Text style={{ color: "#fff" }}>* {" "}</Text>}
                    <Text style={{fontSize: 16, color: 'rgba(0, 0, 0, 1)', marginBottom: 5}}>{name||""}</Text>
                </View>
                <View style={{flexDirection: 'row'}}>
                    <Slider
                        style={{width: 200}}
                        value={this.state.value}
                        minimumValue={minValue}
                        maximumValue={maxValue}
                        step={step}
                        showSpaceDot={showSpaceDot}
                        rangeSlide={rangeSlide}
                        onValueChange={(value) => {
                            this.setState({
                                sliderValue: value
                            })
                        }}
                        //onSlidingComplete={this.onComplete()}
                        //thumbImage={}
                    />
                    <Text style={{fontSize: 16, color: 'rgba(0, 0, 0 , 1)', marginHorizontal: 10}}>{this.state.sliderValue+""}</Text>
                </View>
            </View>
        );
    }
}