Fix switch not emitting value change on first toggle when value set to true #1874
+4
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please select one of the following
Summary
When mounting a
<Switch>
component with thevalue
set totrue
, the first toggle would not emit anonChange
/onValueChange
. This is due to thesetValue
command sent to the native component not triggering the registered action because on AppKit the action is not being called when the value is set programmatically. InSwitch.js
it is expected that the native component would call onChange, which is then used to record the native component's last value.On 0.68 we fixed this by always calling onChange when the native component is toggled, since we don't need to filter out switch value changes that were done programmatically. This allows
Switch.js
to always receive and store the value of the native component.Changelog
[macOS] [FIXED] - Fix switch not emitting value change on first toggle when value set to true
Test Plan
Tested by running RNTester on macOS with paper and using the Switch example. The first toggle of the Switch that is "on" will not result in the value label on the right to change to "off".
Without the fix:
Screen.Recording.2023-07-07.at.00.31.18.mov
With the fix:
Screen.Recording.2023-07-07.at.00.32.02.mov