Skip to content
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

Requires two clicks to turn from true to false. #21

Open
alexbowers opened this issue Jul 24, 2018 · 1 comment
Open

Requires two clicks to turn from true to false. #21

alexbowers opened this issue Jul 24, 2018 · 1 comment

Comments

@alexbowers
Copy link

When using this toggle state, it takes 2 presses to turn from active to inactive the first time, if the value is initialised as active.

<Switch
                                    
                                    value={true}
                                    onChangeValue={(value) => {
                                      console.log(value);
                                      this.setState({ marginValue: !marginValue});
                                     
                                    }}
                                />

I can see it starts in the active manner because of value={true}, but when clicking it the first time, the value from the onChangeValue is also `true. After that, the value represents what I expect it to.

@bimemto
Copy link

bimemto commented Mar 20, 2020

Just replace this line of code in switch.js

constructor(props, context) {
super(props, context);
this.padding = props.padding ? 5 : 0;
this.transformValue = (props.switchWidth - props.buttonWidth - this.padding);
this.state = {
value: props.value, // instead of value: props.defaultValue
transformValue: new Animated.Value(props.value ? this.transformValue : this.padding),
backgroundColor: new Animated.Value(props.value ? 90 : -90),
buttonBackgroundColor: new Animated.Value(props.value ? 90 : -90),
};
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants