-
Notifications
You must be signed in to change notification settings - Fork 138
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
[0.73-stable] Add mouse hover events to RCTTextView
#2143
[0.73-stable] Add mouse hover events to RCTTextView
#2143
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to resolve if we can deterministically create a non-duplicate list of descendantViewTags without relying on throwing away duplicates through a Set, but otherwise this change looks good to me :)
We're now providing the virtual text subviews in a separate array, so this is no longer an issue. |
* Initial implementation * Refactor and dedupe some code * Basic error handling * Clarify comment about mousemove order * Cleanup: enumerate all text attributes at once instead of doing multiple passes * Use *shadow* view traversal for handling nested mouse events * Remove potentially confusing comment * descendantViewTags doesn't need to worry about duplicates * Distinguish between embedded views and virtual text subviews * Scope _virtualSubviews to macOS only * nit: use separate #if blocks for `setTextStorage:...` and `getRectForCharRange:` inclusions * TARGET_OS_OSX blocks for virtualSubviewTags * Remove #if TARGET_OS_OSX blocks, since these changes are potentially upstreamable * Clarify a TODO --------- Co-authored-by: Adam Gleitman <adgleitm@microsoft.com>
…able) (#2149) * [0.73-stable] New events for RCTUIView (#2137) * Move mouse events from RCTView to superclass RCTUIView * Add focus and responder events * Move mouse event implementations to RCTUIView class --------- Co-authored-by: Adam Gleitman <adgleitm@microsoft.com> * [0.73-stable] Add mouse hover events to `RCTTextView` (#2143) * Initial implementation * Refactor and dedupe some code * Basic error handling * Clarify comment about mousemove order * Cleanup: enumerate all text attributes at once instead of doing multiple passes * Use *shadow* view traversal for handling nested mouse events * Remove potentially confusing comment * descendantViewTags doesn't need to worry about duplicates * Distinguish between embedded views and virtual text subviews * Scope _virtualSubviews to macOS only * nit: use separate #if blocks for `setTextStorage:...` and `getRectForCharRange:` inclusions * TARGET_OS_OSX blocks for virtualSubviewTags * Remove #if TARGET_OS_OSX blocks, since these changes are potentially upstreamable * Clarify a TODO --------- Co-authored-by: Adam Gleitman <adgleitm@microsoft.com> * Add an example for Text mouse hover events * Add missing macOS props to Text.d.ts * Fix flow errors * Fix lint errors --------- Co-authored-by: Adam Gleitman <adgleitm@microsoft.com>
Summary:
We have a feature request to allow mouse hover events for subelements inside a
Text
element. This builds off #2137 to get things all set.For now we're only pushing this into 0.73-stable because we want to take more time to consider the native-side architecture for 0.74 onwards.
One slight drawback is that this only works completely properly when there is only one level of onMouseEnter events underneath the main box. For example, if we move the mouse from red to blue in the below example, we see a "leave red" event immediately before an "enter blue" event. The reason for this is that at the native level, allRCTVirtualTextView
s that represent internalText
nodes are direct children of the parentRCTTextView
instead of directly reflecting the DOM hierarchy. This can potentially be fixed by replacing thesuperview
calls insideupdateHoveredSubviewWithEvent:
with something more appropriate, but this is still sufficient for our needs, so I think it's passable as a first iteration of this PR.Test Plan:
Validated using the following example in RNTester: