打开开关按钮后,无法将其关闭

时间:2017-09-17 14:52:53

标签: react-native react-native-android react-native-ios

如何关闭此开关按钮?这是代码:

<Switch
         onValueChange={(value) => this.setState({falseSwitchIsOn: true})}
        onTintColor='#42dff4'
         value={this.state.falseSwitchIsOn} /> 

2 个答案:

答案 0 :(得分:0)

像这样改变

<Switch
         onValueChange={(value) => this.setState({falseSwitchIsOn: value})}
        onTintColor='#42dff4'
         value={this.state.falseSwitchIsOn} /> 

答案 1 :(得分:0)

你应该做的

<Switch
  onValueChange={(value) => this.setState({falseSwitchIsOn: !this.state.falseSwitchIsOn })}
  onTintColor='#42dff4'
  value={this.state.falseSwitchIsOn} /> 

 <Switch
  onValueChange={(value) => this.setState({falseSwitchTwoIsOn: !this.state.falseSwitchTwoIsOn })}
  onTintColor='#42dff4'
  value={this.state.falseSwitchTwoIsOn} />