Skip to content

Adds hook for view managers to capture pointer events - #8495

Merged
23 commits merged into
microsoft:mainfrom
rozele:viewManagerPointerEvents
Sep 29, 2021
Merged

23 commits merged into
microsoft:mainfrom
rozele:viewManagerPointerEvents

Conversation

@rozele

@rozele Eric Rozell (rozele) commented Aug 27, 2021 •

Copy link
Copy Markdown
Contributor

Closes #8499

Currently, there is no way for ViewManagers to capture the pointer to perform it's own pointer event handling. This change introduces a new interface, IViewManagerWithPointerEvents, so third party modules can be notified when the ReactRootView receives pointer events. The behavior is as follows:

ViewManagerBase adds a virtual method:
OnPointerEvent(object sender, ReactPointerEventArgs args)

We have a ReactPointerEventArgs wrapper around PointerRoutedEventArgs that view managers can use to:

  1. Call PreventDefault to suppress the corresponding React event from being emitted
  2. Call ReleaseCapture to force the TouchEventEmitter to release pointer capture (triggering an onTouchCancel event to React Native)
  3. Update the Target property to refine for hit testing

The ReactPointerEventArgs wrapper also includes an enum Kind value for the type of pointer event so we can reduce the number of methods that need to be implemented for this interface.

TODO:

  • Only release pointer in OnPointerMoved rather than invoking OnPointerConcluded.
  • Consolidate parent traversals so we only traverse shadow node tree once per event.
  • Add custom view manager example that uses this API. N/A since we now leverage these APIs in core view managers
  • Determine if IViewManagerWithPointerEvents should participate in onMouseEnter / onMouseLeave events: The current approach should start onMouseEnter / onMouseLeave events at the ReactPointerEventArgs.Target() element.

We will need to update a few other PRs to leverage these APIs once they merge:

Microsoft Reviewers: Open in CodeFlow

@rozele
Eric Rozell (rozele) requested a review from a team as a code owner August 27, 2021 19:07
@acoates-ms

Copy link
Copy Markdown
Contributor

Alicia Drummond (@FalseLobster) you might want to look at this - Anyone else that should be looped into this?

@asklar

Alexander Sklar (asklar) commented Aug 27, 2021 •

Copy link
Copy Markdown
Member

Steven Moyes (@stmoy) Chris Glein (@chrisglein) fyi
Eric Rozell (@rozele) I created an issue to track discussing the design: #8499

Comment thread vnext/Microsoft.ReactNative/ABIViewManager.cpp
Comment thread vnext/Microsoft.ReactNative/ReactPointerEventArgs.idl Outdated
Comment thread vnext/Microsoft.ReactNative/ReactPointerEventArgs.idl
Comment thread vnext/Microsoft.ReactNative/ABIViewManager.cpp Outdated
Comment thread vnext/Microsoft.ReactNative/ABIViewManager.cpp Outdated
Comment thread vnext/Microsoft.ReactNative/ReactPointerEventArgs.h Outdated
Eric Rozell (rozele) added a commit to rozele/react-native-windows that referenced this pull request Sep 1, 2021
Comment thread vnext/Microsoft.ReactNative/Views/TouchEventHandler.cpp Outdated
@rozele
Eric Rozell (rozele) force-pushed the viewManagerPointerEvents branch 7 times, most recently from 9c89083 to 2397fcc Compare September 3, 2021 02:19
Comment thread vnext/Microsoft.ReactNative/Views/TouchEventHandler.cpp
Comment thread vnext/Microsoft.ReactNative/Views/TouchEventHandler.cpp Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, in current form with minimal API surface.

@NickGerleman

Copy link
Copy Markdown
Contributor

@msftbot merge in 24 hours

@ghost ghost added the AutoMerge Causes a PR to be automatically merged once all requirements are passed (label drives bot activity) label Sep 28, 2021
@ghost

Copy link
Copy Markdown

Hello Nick Gerleman (@NickGerleman)!

Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:

  • I won't merge this pull request until after the UTC date Wed, 29 Sep 2021 20:32:14 GMT, which is in 1 day

If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you".

Comment thread vnext/Microsoft.ReactNative/IViewManager.idl
Comment thread vnext/Microsoft.ReactNative/ReactPointerEventArgs.idl Outdated
Comment thread vnext/Microsoft.ReactNative/ReactPointerEventArgs.idl Outdated

@asklar Alexander Sklar (asklar) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, let's just update the doc strings so it's a little more clear when these things are triggered/used

@ghost ghost added Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) and removed Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) AutoMerge Causes a PR to be automatically merged once all requirements are passed (label drives bot activity) labels Sep 28, 2021
@rozele

Eric Rozell (rozele) commented Sep 29, 2021 •

Copy link
Copy Markdown
Contributor Author

Alexander Sklar (@asklar) - Updated the DOC_STRINGS in 235e110

@rozele
Eric Rozell (rozele) force-pushed the viewManagerPointerEvents branch 2 times, most recently from 1903618 to 235e110 Compare September 29, 2021 00:27

@asklar Alexander Sklar (asklar) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks Eric Rozell (@rozele), and for updating the docs : )

@asklar Alexander Sklar (asklar) added the AutoMerge Causes a PR to be automatically merged once all requirements are passed (label drives bot activity) label Sep 29, 2021
@ghost

Copy link
Copy Markdown

Hello Alexander Sklar (@asklar)!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost
ghost merged commit 4bc8637 into microsoft:main Sep 29, 2021
Eric Rozell (rozele) added a commit to rozele/react-native-windows that referenced this pull request Jun 27, 2022
In microsoft#8495, we added
an interface for 3rd party view managers to override pointer event
handling in the TouchEventHandler module from RNW. The features of this
PR supported press events on selectable text, but to generalize this
further, we need to allow 3rd party view managers to conditionally
cancel pointer event sequences and prevent press events.

This change adds the ability for view managers implementing the
IViewManagerWithPointerEvents interface to change an "End" event to a
"Cancel" event to achieve just that.

Fixes microsoft#10202
ghost pushed a commit that referenced this pull request Aug 15, 2022
* Adds gesture cancellation to pointer event handling

In #8495, we added
an interface for 3rd party view managers to override pointer event
handling in the TouchEventHandler module from RNW. The features of this
PR supported press events on selectable text, but to generalize this
further, we need to allow 3rd party view managers to conditionally
cancel pointer event sequences and prevent press events.

This change adds the ability for view managers implementing the
IViewManagerWithPointerEvents interface to change an "End" event to a
"Cancel" event to achieve just that.

Fixes #10202

* Change files
Eric Rozell (rozele) added a commit to rozele/react-native-windows that referenced this pull request Oct 23, 2022
…#10203)

In microsoft#8495, we added
an interface for 3rd party view managers to override pointer event
handling in the TouchEventHandler module from RNW. The features of this
PR supported press events on selectable text, but to generalize this
further, we need to allow 3rd party view managers to conditionally
cancel pointer event sequences and prevent press events.

This change adds the ability for view managers implementing the
IViewManagerWithPointerEvents interface to change an "End" event to a
"Cancel" event to achieve just that.

Fixes microsoft#10202
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Mouse AutoMerge Causes a PR to be automatically merged once all requirements are passed (label drives bot activity)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

View managers should be able to handle/capture pointer events

4 participants