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

Fix switch not emitting value change on first toggle when value set to true #1874

Closed
wants to merge 1 commit into from

Conversation

lenaic
Copy link

@lenaic lenaic commented Jul 6, 2023

Please select one of the following

  • I am removing an existing difference between facebook/react-native and microsoft/react-native-macos 👍
  • I am cherry-picking a change from Facebook's react-native into microsoft/react-native-macos 👍
  • I am making a fix / change for the macOS implementation of react-native
  • I am making a change required for Microsoft usage of react-native

Summary

When mounting a <Switch> component with the value set to true, the first toggle would not emit an onChange/onValueChange. This is due to the setValue 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. In Switch.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

@lenaic lenaic requested a review from a team as a code owner July 6, 2023 22:46
@Saadnajmi
Copy link
Collaborator

Duplicate of #1871 ?

@lenaic
Copy link
Author

lenaic commented Jul 7, 2023

Duplicate of #1871 ?

You're right, it's fixing the same issue. In less of a brute-force way.

@lenaic lenaic closed this Jul 7, 2023
@lenaic lenaic deleted the switch-value-onchange-fix branch August 7, 2023 15:24
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

Successfully merging this pull request may close these issues.

2 participants