fix(0.76, macOS): reconcile coordinate systems for mouse events (#2403) #2405
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.
On iOS, -hitTest:withEvent: works with the coordinate system of the view that is being hit tested. On the other hand, on macOS, -hitTest: works with the coordinate system of the superview. React Native macOS currently appears to mix these two coordinate systems, which can lead to unexpected behaviors, one of which that I have personally observed is
mouseDown:
events being delievered to a view that does not pass OS-level hit testing (e.g. the hit point is completely outside of the view that was allegedly hit, even if accounting for not clipping to bounds and any possible descendant view larger than the hit view).To enforce consistent behavior, we will use the macOS style coordinate system for APIs that follow the macOS signature, and the iOS style coordinate system for APIs that follow the iOS signature, or are obviously React Native APIs. Several APIs were scrubbed for calls and implementation.
The following APIs shall work with superview's coordinate space:
- hitTest:
The following APIs shall work with the view's (i.e. self) coordinate space:
RCTUIViewHitTestWithEvent
- reactTagAtMouseLocationFromEvent:
- reactTagAtPoint:
- hitTest:withEvent:
- betterHitTest:withEvent:
- pointInside:withEvent:
With the proper coordinate system usage, we no longer need new RN components inheriting from NSView to behave in special manners. Updating documentation to reflect that.
Manual Testing:
Summary:
Test Plan: