From 6de994a57314026128813ec7e8fca873fe7cf0e5 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Wed, 26 Feb 2025 15:36:24 -0800 Subject: [PATCH 1/3] Components do not lost hover state if pointer leaves window before it leaves the component --- .../Composition/CompositionEventHandler.cpp | 43 +++++++++++++++++++ .../Composition/CompositionEventHandler.h | 4 ++ 2 files changed, 47 insertions(+) diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp index ece0121fcc3..d511ae909b7 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp @@ -196,6 +196,20 @@ void CompositionEventHandler::Initialize() noexcept { } }); + m_pointerExitedToken = pointerSource.PointerExited([wkThis = weak_from_this()]( + winrt::Microsoft::UI::Input::InputPointerSource const &, + winrt::Microsoft::UI::Input::PointerEventArgs const &args) { + if (auto strongThis = wkThis.lock()) { + if (auto strongRootView = strongThis->m_wkRootView.get()) { + if (strongThis->SurfaceId() == -1) + return; + auto pp = winrt::make( + args.CurrentPoint(), strongRootView.ScaleFactor()); + strongThis->onPointerExited(pp, args.KeyModifiers()); + } + } + }); + m_pointerCaptureLostToken = pointerSource.PointerCaptureLost([wkThis = weak_from_this()]( winrt::Microsoft::UI::Input::InputPointerSource const &, @@ -1063,6 +1077,35 @@ void CompositionEventHandler::onPointerMoved( } } +void CompositionEventHandler::onPointerExited( + const winrt::Microsoft::ReactNative::Composition::Input::PointerPoint &pointerPoint, + winrt::Windows::System::VirtualKeyModifiers keyModifiers) noexcept { + if (SurfaceId() == -1) + return; + + int pointerId = pointerPoint.PointerId(); + auto position = pointerPoint.Position(); + + if (std::shared_ptr fabricuiManager = + ::Microsoft::ReactNative::FabricUIManager::FromProperties(m_context.Properties())) { + facebook::react::Tag tag = -1; + facebook::react::Point ptLocal, ptScaled; + getTargetPointerArgs(fabricuiManager, pointerPoint, tag, ptScaled, ptLocal); + + tag = -1; + + auto args = winrt::make( + m_context, tag, pointerPoint, keyModifiers); + + facebook::react::PointerEvent pointerEvent = CreatePointerEventFromIncompleteHoverData(ptScaled, ptLocal); + + auto handler = [](std::vector &eventPathViews) { + }; + + HandleIncomingPointerEvent(pointerEvent, nullptr, pointerPoint, keyModifiers, handler); + } +} + void CompositionEventHandler::onPointerPressed( const winrt::Microsoft::ReactNative::Composition::Input::PointerPoint &pointerPoint, winrt::Windows::System::VirtualKeyModifiers keyModifiers) noexcept { diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h index 1826338fadb..be9cfa44b79 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h @@ -57,6 +57,9 @@ class CompositionEventHandler : public std::enable_shared_from_this Date: Wed, 26 Feb 2025 15:36:43 -0800 Subject: [PATCH 2/3] format --- .../Fabric/Composition/CompositionEventHandler.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp index d511ae909b7..e7d646f6bff 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp @@ -1099,8 +1099,7 @@ void CompositionEventHandler::onPointerExited( facebook::react::PointerEvent pointerEvent = CreatePointerEventFromIncompleteHoverData(ptScaled, ptLocal); - auto handler = [](std::vector &eventPathViews) { - }; + auto handler = [](std::vector &eventPathViews) {}; HandleIncomingPointerEvent(pointerEvent, nullptr, pointerPoint, keyModifiers, handler); } From 02c0f87ed917db17265387465934cb1862d4c841 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Wed, 26 Feb 2025 15:36:55 -0800 Subject: [PATCH 3/3] Change files --- ...ative-windows-61361492-e98e-45f9-931a-795d9a86919b.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/react-native-windows-61361492-e98e-45f9-931a-795d9a86919b.json diff --git a/change/react-native-windows-61361492-e98e-45f9-931a-795d9a86919b.json b/change/react-native-windows-61361492-e98e-45f9-931a-795d9a86919b.json new file mode 100644 index 00000000000..59b2c8f3d59 --- /dev/null +++ b/change/react-native-windows-61361492-e98e-45f9-931a-795d9a86919b.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Components do not lost hover state if pointer leaves window before it leaves the component", + "packageName": "react-native-windows", + "email": "30809111+acoates-ms@users.noreply.github.com", + "dependentChangeType": "patch" +}