Fix switch being stuck in intermidiate state on Android

Summary:
This diff fixes the bug of the switch component on Android being stuck in the middle when a user releases their finger whily dragging the thumb.

When a user releases their finger while dragging the thumb, `setChecked` will be called and if `mAllowChange` is set to false, `super.setChecked` is never called. The supper method will actually make sure the thumb will be animated to the correct edge. Without calling the super method, the thumb might stay in the middle of the switch where a user released their finger.

The fix had to be applied both to ReactSwitch and FbReactSwitchCompat.

One more fix had to be made to FbReactSwitchCompat since D5884661 was applied to ReactSwitch, but not to FbReactSwitchCompat:

if (mAllowChange && **isChecked() != checked**) {
...
}

Reviewed By: mdvacca

Differential Revision: D15535611

fbshipit-source-id: 22ca1fe3fa993ae65cbd677bfae2208a02c368d4
This commit is contained in:
Oleksandr Melnykov
2019-05-30 10:32:51 -07:00
committed by Facebook Github Bot
parent 33ee6f8b99
commit aac95b409b
@@ -37,6 +37,11 @@ import javax.annotation.Nullable;
mAllowChange = false;
super.setChecked(checked);
setTrackColor(checked);
} else {
// Even if mAllowChange is set to false or the checked value hasn't changed, we still must
// call the super method, since it will make sure the thumb is moved back to the correct edge.
// Without calling the super method, the thumb might stuck in the middle of the switch.
super.setChecked(isChecked());
}
}