Skip to content

Adds option to allow ViewManagers to capture pointer - #8969

Merged
Chiara Mooney (chiaramooney) merged 2 commits into
microsoft:mainfrom
rozele:allowUncaptured
Nov 8, 2023
Merged

Chiara Mooney (chiaramooney) merged 2 commits into
microsoft:mainfrom
rozele:allowUncaptured

Conversation

@rozele

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

Copy link
Copy Markdown
Contributor

Adds property to ReactPointerEventArgs to allow view managers to capture the pointer while still allowing RN to emit events to JS. XAML only allows capturing the pointer on PointerPressed, so this would allow, for example, a view manager that supports custom native drag behaviors that have a threshold for action (and when that threshold is not exceeded,
the gesture is handled by RN).

Microsoft Reviewers: Open in CodeFlow
@rozele
Eric Rozell (rozele) requested a review from a team as a code owner October 27, 2021 17:53
@rozele

Copy link
Copy Markdown
Contributor Author

We use this in our app for a view that responds implements native dragging that goes outside the bounds of the view. We need to capture the pointer so it continues to receive PointerMoved events after the pointer has left the bounds of the view, but we also only trigger the drag after a certain move threshold has been reached - otherwise, the gesture is treated as a "regular" RN click.

"@PointerEventKind.End event is received before a drag threshold is hit."
)
Boolean AllowUncaptured {
get;

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.

When we have similar concepts in Windows, we call it Handled, and if you don't set it, then the system proceeds to handle it. So maybe rename this to Handled?

@rozele Eric Rozell (rozele) Oct 29, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's a bit more nuanced than Handled. Presumably, if we wanted to prevent the TouchEventHandler from processing an event, we could just subscribe PointerPressed on a view and mark it Handled.

This is a related but slightly different concept. TouchEventHandler captures the pointer on PointerPressed (for good reason, so we can track gestures that extend beyond the bounds of the window). If the capture fails, we currently do not track the pointer to fire onTouchStart/Move/End/Cancel. This is an implementation detail of react-native-Windows, not necessarily a XAML concept.

What we needed was an ability to tell the TouchEventHandler that it's okay if it can't capture the pointer, continue processing as if that had succeeded.

I'm open to better naming alternatives:

  • Prevent(Root)Capture
  • Should(Root)Capture
  • ProceedWithoutCapture
  • ...

The reason I went for AllowUncaptured is that it felt like it could also have the semantics to terminate the gesture in the PointerMoved event when it stops being set by the view manager for subsequent OnPointerEvent callbacks, but I will say this adds complexity to the API. I (now) think that since capture is something that only needs to be dealt with during the PointerPressed event in XAML - it's counter-intuitive to have to keep setting AllowUncaptured to get the move and end events through to React JS. Once we land on a better name, I'll fix that up as well.

@chrisglein

Chris Glein (chrisglein) commented Dec 14, 2022 •

Copy link
Copy Markdown
Member

Eric Rozell (@rozele) We're looking to unstick this PR that's been open for more than a year now. How does it resonate for you now? Does it still feel like the right change? Have we thought through the alignment with native expectations around Handled and such? Looking for your take and/or a smidge more detail so we know how to take this one.

@chrisglein Chris Glein (chrisglein) added the Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) label Dec 14, 2022
@rozele

Eric Rozell (rozele) commented Dec 20, 2022 •

Copy link
Copy Markdown
Contributor Author

Chris Glein (@chrisglein) - we already support working around Handled events, specifically to make selectable text pressable. This change is slightly different. The implication isn't that we necessarily want to workaround more Handled events, but rather to allow custom native components to capture the pointer. The idea is that a custom component would only set the AllowUncaptured flag if it wanted to capture the pointer while also allowing React gesture events to flow. To me, this is pretty low risk, I think the hang up was just on what to call the property. Handled doesn't feel right to me, AllowUncaptured seems like the most concise way to express the semantics, a more verbose name would be AllowReactViewToCapturePointerButStillFireGestureEvents :).

This may also be a bit too product specific, but it solves a "general" problem that can't be solved without it, which is that custom React Native components have no way to capture a pointer for potential synchronous handling without impacting / preventing normal React gesture handling, it's just a question on how many apps would actually need this behavior.

@ghost ghost removed the Needs: Author Feedback The issue/PR needs activity from its author (label drives bot activity) label Dec 20, 2022
@chiaramooney Chiara Mooney (chiaramooney) added the Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) label Jan 18, 2023
@chiaramooney

Copy link
Copy Markdown
Contributor

Discussed in PR Triage. With the priority to move to Fabric, we are opting not to take this change for the Paper architecture.

@jonthysell Jon Thysell (jonthysell) removed the Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) label Jun 5, 2023
@rozele

Eric Rozell (rozele) commented Nov 6, 2023 •

Copy link
Copy Markdown
Contributor Author

Re-opening, as it's a relatively trivial change on an experimental public interface that keeps the delta smaller in our fork of react-native-windows.

Adds property to ReactPointerEventArgs to allow view managers to capture
the pointer while still allowing RN to emit events to JS. XAML only
allows capturing the pointer on PointerPressed, so this would allow, for
example, a view manager that supports custom native drag behaviors that
have a threshold for action (and when that threshold is not exceeded,
the gesture is handled by RN).
@chrisglein Chris Glein (chrisglein) added the Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) label Nov 6, 2023
@acoates-ms

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines successfully started running 1 pipeline(s).
@acoates-ms acoates-ms removed Needs: Dev Design Needs: Attention 👋 An issue that had been tagged "Needs: Author Feedback" has received activity (label applied by bot) labels Nov 8, 2023
@chiaramooney
Chiara Mooney (chiaramooney) merged commit 0f6bdf3 into microsoft:main Nov 8, 2023
@rozele
Eric Rozell (rozele) deleted the allowUncaptured branch November 9, 2023 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

6 participants