Skip to content

Commit 684db13

Browse files
authored
Limit Yoga layout to relevant root on resize (#10580)
* Limit Yoga layout to relevant root on resize Recalculation of Yoga layout due to root view size change does not require that we re-run layout on all roots. It also does not require that we invoke UpdateLayout on any new nodes (as a resize operation is independent of a batch of UIManager operations). This change limits the scope of Yoga calculation and application of Yoga results to XAML views to only the root view that changed size. This optimization primarily impacts apps with multiple windows, but can also benefit any React Native Windows app with multiple roots. * Change files
1 parent e645586 commit 684db13

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Limit Yoga layout to relevant root on resize",
4+
"packageName": "react-native-windows",
5+
"email": "erozell@outlook.com",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative/Modules/NativeUIManager.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,23 +217,26 @@ void NativeUIManager::AddRootView(ShadowNode &shadowNode, facebook::react::IReac
217217
SystraceSection s("NativeUIManager::AddRootView");
218218
auto xamlRootView = static_cast<IXamlRootView *>(pReactRootView);
219219
XamlView view = xamlRootView->GetXamlView();
220+
const auto rootTag = shadowNode.m_tag;
220221
m_tagsToXamlReactControl.emplace(
221-
shadowNode.m_tag,
222+
rootTag,
222223
winrt::weak_ref<winrt::Microsoft::ReactNative::ReactRootView>(
223224
view.as<winrt::Microsoft::ReactNative::ReactRootView>()));
224225

225226
// Push the appropriate FlowDirection into the root view.
226227
view.as<xaml::FrameworkElement>().FlowDirection(
227228
I18nManager::IsRTL(m_context.Properties()) ? xaml::FlowDirection::RightToLeft : xaml::FlowDirection::LeftToRight);
228229

229-
m_tagsToYogaNodes.emplace(shadowNode.m_tag, make_yoga_node(m_yogaConfig));
230+
m_tagsToYogaNodes.emplace(rootTag, make_yoga_node(m_yogaConfig));
230231

231232
auto element = view.as<xaml::FrameworkElement>();
232-
Microsoft::ReactNative::SetTag(element, shadowNode.m_tag);
233+
Microsoft::ReactNative::SetTag(element, rootTag);
233234

234235
// Add listener to size change so we can redo the layout when that happens
235-
m_sizeChangedVector.push_back(
236-
view.as<xaml::FrameworkElement>().SizeChanged(winrt::auto_revoke, [this](auto &&, auto &&) { DoLayout(); }));
236+
m_sizeChangedVector.push_back(view.as<xaml::FrameworkElement>().SizeChanged(
237+
winrt::auto_revoke, [this, rootTag](auto &&, xaml::SizeChangedEventArgs const &args) {
238+
ApplyLayout(rootTag, args.NewSize().Width, args.NewSize().Height);
239+
}));
237240
}
238241

239242
void NativeUIManager::removeRootView(Microsoft::ReactNative::ShadowNode &shadow) {

0 commit comments

Comments
 (0)