Send JS blur/focus events when switching to another NSWindow #2323
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.
Summary:
Consider a React Native experience occurring inside an
NSPanel
. On macOS, thisNSPanel
will keep track of its own first responder. In other words, if you click off that panel and into somewhere else (be it anotherNSWindow
in the same app or another app altogether), theNSPanel
never relinquishes its first responder, so we never send the blur or focus events to the JS side.In this example of blur and focus events in Web, we see that the blur and focus events still take effect when switching windows. Therefore, it's reasonable to try to do the same in react-native-macos. We only send the events at the JS level; as far as the OS is concerned, we leave the first responders themselves intact.
Test Plan:
This was tested with the help of react-native-test-app. Specifically, I added a React Native experience hosted in an
NSPanel
and added some<Pressable>
elements withonBlur
andonFocus
events. Upon switching windows, we do indeed see the blur and focus events coming through, and eachNSWindow
properly maintains its own first responder as desired.