diff --git a/change/react-native-windows-c628c673-e01f-4887-9fcf-b1e5c468d311.json b/change/react-native-windows-c628c673-e01f-4887-9fcf-b1e5c468d311.json new file mode 100644 index 00000000000..57c9f9fa255 --- /dev/null +++ b/change/react-native-windows-c628c673-e01f-4887-9fcf-b1e5c468d311.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Fix CompositionHwndHost initialization order: ResizePolicy is now set before Connect and ScaleFactor before the island is connected, matching the ReactNativeWindow reference pattern, so that secondary windows render with correct DPI-aware touch coordinates.", + "packageName": "react-native-windows", + "email": "gordomacmaster@gmail.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionHwndHost.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionHwndHost.cpp index c095f1d4dad..eaf49396132 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionHwndHost.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionHwndHost.cpp @@ -34,16 +34,19 @@ void CompositionHwndHost::Initialize(uint64_t hwnd) noexcept { ReactViewHost().ReactNativeHost().InstanceSettings().Properties()); m_compRootView = winrt::Microsoft::ReactNative::ReactNativeIsland(compositor); - auto bridge = winrt::Microsoft::UI::Content::DesktopChildSiteBridge::Create( + m_bridge = winrt::Microsoft::UI::Content::DesktopChildSiteBridge::Create( compositor, winrt::Microsoft::UI::GetWindowIdFromWindow(m_hwnd)); - auto island = m_compRootView.Island(); - - bridge.Connect(island); - bridge.Show(); + // ResizePolicy must be set before Connect so the bridge configures the + // island's coordinate space with correct DPI awareness (matches + // ReactNativeWindow::ContentSiteBridge initialization order). + m_bridge.ResizePolicy(winrt::Microsoft::UI::Content::ContentSizePolicy::ResizeContentToParentWindow); + auto island = m_compRootView.Island(); m_compRootView.ScaleFactor(ScaleFactor()); - bridge.ResizePolicy(winrt::Microsoft::UI::Content::ContentSizePolicy::ResizeContentToParentWindow); + + m_bridge.Connect(island); + m_bridge.Show(); m_compRootView.ReactViewHost(std::move(m_reactViewHost)); m_compRootView.ScaleFactor(ScaleFactor()); diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionHwndHost.h b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionHwndHost.h index f0dfda5dbfd..7f3ea7f04a6 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionHwndHost.h +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionHwndHost.h @@ -5,6 +5,7 @@ #include "CompositionHwndHost.g.h" #include +#include #include #include "ReactHost/React.h" @@ -34,6 +35,7 @@ struct CompositionHwndHost : CompositionHwndHostT { HWND m_hwnd; winrt::Microsoft::ReactNative::ReactNativeIsland m_compRootView{nullptr}; + winrt::Microsoft::UI::Content::DesktopChildSiteBridge m_bridge{nullptr}; LONG m_height{0}; LONG m_width{0};