Repository navigation
Adds option to allow ViewManagers to capture pointer - #8969
Conversation
|
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
2afc416 to
e8e985b
Compare
|
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. |
|
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 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. |
e8e985b to
58419ee
Compare
|
Discussed in PR Triage. With the priority to move to Fabric, we are opting not to take this change for the Paper architecture. |
|
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).
58419ee to
6011bf1
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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