Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "applying package updates ***NO_CI***",
"packageName": "react-native-windows",
"email": "erozell@outlook.com",
"dependentChangeType": "patch"
}
8 changes: 8 additions & 0 deletions vnext/Microsoft.ReactNative/ReactPointerEventArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ void ReactPointerEventArgs::Target(winrt::IInspectable const &target) noexcept {
m_target = target;
}

bool ReactPointerEventArgs::AllowUncaptured() const noexcept {
return m_allowUncaptured;
}

void ReactPointerEventArgs::AllowUncaptured(bool allowUncaptured) noexcept {
m_allowUncaptured = allowUncaptured;
}

ReactPointerEventArgs::ReactPointerEventArgs(
PointerEventKind kind,
xaml::Input::PointerRoutedEventArgs const &args) noexcept
Expand Down
4 changes: 4 additions & 0 deletions vnext/Microsoft.ReactNative/ReactPointerEventArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ struct ReactPointerEventArgs : ReactPointerEventArgsT<ReactPointerEventArgs> {
winrt::IInspectable Target() const noexcept;
void Target(winrt::IInspectable const &target) noexcept;

bool AllowUncaptured() const noexcept;
void AllowUncaptured(bool allowUncaptured) noexcept;

// Internal use
ReactPointerEventArgs(PointerEventKind kind, xaml::Input::PointerRoutedEventArgs const &args) noexcept;

private:
PointerEventKind m_kind;
xaml::Input::PointerRoutedEventArgs const &m_args;
winrt::IInspectable m_target{nullptr};
bool m_allowUncaptured{false};
};

} // namespace winrt::Microsoft::ReactNative::implementation
12 changes: 12 additions & 0 deletions vnext/Microsoft.ReactNative/ReactPointerEventArgs.idl
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,17 @@ namespace Microsoft.ReactNative {
get;
set;
};
DOC_STRING(
"Gets or sets a flag that allows the ReactRootView to handle pointer "
"events even when it does not capture the pointer. This is particularly "
"useful for view managers that seek to capture the pointer to handle "
"move events for a gesture (e.g., dragging), but conditionally may "
"allow the ReactRootView to emit events (e.g., if the "
"@PointerEventKind.End event is received before a drag threshold is hit."
)
Comment thread
rozele marked this conversation as resolved.
Resolved
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.

set;
};
}
} // namespace Microsoft.ReactNative
2 changes: 1 addition & 1 deletion vnext/Microsoft.ReactNative/Views/TouchEventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void TouchEventHandler::OnPointerPressed(
return;
}

if (m_xamlView.as<xaml::FrameworkElement>().CapturePointer(args.Pointer())) {
if (reactArgs.AllowUncaptured() || m_xamlView.as<xaml::FrameworkElement>().CapturePointer(args.Pointer())) {
assert(!tagsForBranch.empty());
const auto tag = tagsForBranch.front();

Expand Down