Skip to content

Commit

Permalink
Adds gesture cancellation to pointer event handling (#10203)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rozele committed Aug 15, 2022
1 parent 7ee2363 commit 1231233
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Adds gesture cancellation to pointer event handling",
"packageName": "react-native-windows",
"email": "erozell@outlook.com",
"dependentChangeType": "patch"
}
14 changes: 12 additions & 2 deletions vnext/Microsoft.ReactNative/ReactPointerEventArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,18 @@ PointerEventKind ReactPointerEventArgs::Kind() const noexcept {
}

void ReactPointerEventArgs::Kind(PointerEventKind kind) noexcept {
// The only event type change that is supported is CaptureLost to End.
assert(kind == PointerEventKind::End && m_kind == PointerEventKind::CaptureLost);
// The only event type transitions that are supported are:
// 1. PointerEventKind::CaptureLost to PointerEventKind::End to support cases
// where XAML firing the CaptureLost event should be treated as a gesture
// completion event, e.g., for pointer events in selectable text that do
// not result in text selection.
// 2. PointerEventKind::End to PointerEventKind::Cancel to support cases
// where a custom view manager implementing `IViewManagerWithPointerEvents`
// wants to cancel a gesture, e.g., for a custom drag handle where the end
// of the gesture should not be treated as a completed press event.
assert(
(kind == PointerEventKind::End && m_kind == PointerEventKind::CaptureLost) ||
(kind == PointerEventKind::Cancel && m_kind == PointerEventKind::End));
m_kind = kind;
}

Expand Down

0 comments on commit 1231233

Please sign in to comment.