一旦在React Native中使用,请禁用Slider

时间:2019-04-12 18:43:59

标签: javascript reactjs slider native

我正在使用rn-vertical-slider,一旦使用完毕(即一旦用户完成),就必须禁用它。我该怎么办??

1 个答案:

答案 0 :(得分:0)

该库已经提供了禁用道具。您需要在代码中进行以下更改。

使构造函数具有默认值为false的isDisable状态

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

}

向onChange回调道具中添加函数

_checkMaximunSliderValue=(value)=>{
 If(value==100){ 
this.setState({isDisable:true})
}
}

*“在禁用道具中设置this.state.isDisable **

<VerticalSlider
  value={1}
  disabled={this.state.isDisable}
  min={0}
  max={100}
  onChange={(value: number) => {
    this._checkMaximunSliderValue(value);
  }}
  onComplete={(value: number) => {
    console.log("COMPLETE", value);
  }}
  width={50}
  height={300}
  step={1}
  borderRadius={5}
  minimumTrackTintColor={"gray"}
  maximumTrackTintColor={"tomato"}
  showBallIndicator
  ballIndicatorColor={"gray"}
  ballIndicatorTextColor={"white"}
/>;