-
Notifications
You must be signed in to change notification settings - Fork 95
Can I change switch value programmatically? #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
emmming, I will do it recently and please give me some time. |
It's unnecessary to add animation when changing value programmatically. If u have to do it, the following code should be done: componentWillReceiveProps (nextProps) {
if (nextProps === this.props) {
return
}
// componentWillReceiveProps will still be triggered if
// render function of father component is triggered.
// Thus, toggleSwitch will be executed without two-way bind.
if (typeof nextProps.value !== 'undefined' && nextProps.value !== this.props.value) {
this.animateHandler(this.handlerSize * SCALE, () => {
this.toggleSwitch(true)
})
}
} The SCALE is a variable valued 6 / 5. this.animateHandler(this.handlerSize * SCALE, () => {
setTimeout(() => {
this.toggleSwitch(true)
}, yourTime)
}) |
I think I already did what @cnakh wanted in Nov, 2017. switch1 shows myState1, switch2 shows myState2. When switch1 is toggled, |
@cnakh yes you can. you need to ref the comp. Ex:
when you call the changeValue function, your switch will change. @diaojinggang when you update state all page will be rendered again. It can not be necessary but if you have many switch your state will be too crowded. I think the best way is the ref. |
Your component is very nice.
I have two toggle switch, if one on, the other one is off.
So when I click on the toggle switch it trigger the other to change it state.
How can I make the switch change value and animate by programmatically?
The text was updated successfully, but these errors were encountered: