diff --git a/change/react-native-windows-f2b5ffe0-c976-4f9e-820f-527bdbcf4f7a.json b/change/react-native-windows-f2b5ffe0-c976-4f9e-820f-527bdbcf4f7a.json new file mode 100644 index 00000000000..098e118b6fa --- /dev/null +++ b/change/react-native-windows-f2b5ffe0-c976-4f9e-820f-527bdbcf4f7a.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Fix issue when calling arrange on an RN Island during load", + "packageName": "react-native-windows", + "email": "30809111+acoates-ms@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Microsoft.ReactNative/Fabric/ComponentView.cpp b/vnext/Microsoft.ReactNative/Fabric/ComponentView.cpp index 3161fa2cb7a..b1d0593b3c9 100644 --- a/vnext/Microsoft.ReactNative/Fabric/ComponentView.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/ComponentView.cpp @@ -279,7 +279,10 @@ void ComponentView::parent(const winrt::Microsoft::ReactNative::ComponentView &p m_parent = parent; if (!parent) { if (oldRootView && oldRootView->GetFocusedComponent() == *this) { - oldRootView->TrySetFocusedComponent(oldParent, winrt::Microsoft::ReactNative::FocusNavigationDirection::None); + oldRootView->TrySetFocusedComponent( + oldParent, + winrt::Microsoft::ReactNative::FocusNavigationDirection::None, + true /*forceNoSelectionIfCannotMove*/); } } if (parent) { diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp index 33812dab916..29224ad263a 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp @@ -771,7 +771,7 @@ winrt::Windows::Foundation::Size ReactNativeIsland::Measure( facebook::react::LayoutConstraints constraints; ApplyConstraints(layoutConstraints, constraints); - if (m_isInitialized && m_rootTag != -1) { + if (m_isInitialized && m_rootTag != -1 && m_hasRenderedVisual) { if (auto fabricuiManager = ::Microsoft::ReactNative::FabricUIManager::FromProperties( winrt::Microsoft::ReactNative::ReactPropertyBag(m_context.Properties()))) { facebook::react::LayoutContext context; @@ -802,7 +802,7 @@ void ReactNativeIsland::Arrange( facebook::react::LayoutConstraints fbLayoutConstraints; ApplyConstraints(layoutConstraints, fbLayoutConstraints); - if (m_isInitialized && m_rootTag != -1 && !m_isFragment) { + if (m_isInitialized && m_rootTag != -1 && !m_isFragment && m_hasRenderedVisual) { if (auto fabricuiManager = ::Microsoft::ReactNative::FabricUIManager::FromProperties( winrt::Microsoft::ReactNative::ReactPropertyBag(m_context.Properties()))) { facebook::react::LayoutContext context; diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp index a9ebbeae7fc..3c0bc5c42ba 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp @@ -120,7 +120,8 @@ bool RootComponentView::NavigateFocus(const winrt::Microsoft::ReactNative::Focus bool RootComponentView::TrySetFocusedComponent( const winrt::Microsoft::ReactNative::ComponentView &view, - winrt::Microsoft::ReactNative::FocusNavigationDirection direction) noexcept { + winrt::Microsoft::ReactNative::FocusNavigationDirection direction, + bool forceNoSelectionIfCannotMove /*= false*/) noexcept { auto target = view; auto selfView = winrt::get_self(target); if (selfView && !selfView->focusable()) { @@ -128,7 +129,7 @@ bool RootComponentView::TrySetFocusedComponent( direction == winrt::Microsoft::ReactNative::FocusNavigationDirection::Previous) ? FocusManager::FindLastFocusableElement(target) : FocusManager::FindFirstFocusableElement(target); - if (!target) + if (!target && !forceNoSelectionIfCannotMove) return false; selfView = winrt::get_self(target); } @@ -154,6 +155,8 @@ bool RootComponentView::TrySetFocusedComponent( winrt::get_self(losingFocusArgs.NewFocusedComponent()) ->rootComponentView() ->SetFocusedComponent(gettingFocusArgs.NewFocusedComponent(), direction); + } else { + SetFocusedComponent(nullptr, direction); } return true; diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h b/vnext/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h index 59102f2f744..9dc96885008 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h @@ -32,7 +32,8 @@ struct RootComponentView : RootComponentViewT