Skip to content

Commit 2b95148

Browse files
committed
fix: Fix UpdateLayout measuring to 0x0 if called too early
1 parent 7411526 commit 2b95148

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/Uno.UI/UI/Xaml/UIElement.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,17 +362,31 @@ public void UpdateLayout()
362362
{
363363
_isInUpdateLayout = true;
364364

365+
// On UWP, the UpdateLayout method has an overload which accepts the desired size used by the window/app to layout the visual tree,
366+
// then this overload without parameter is only using the internally cached last desired size.
367+
// With Uno this method is not used for standard layouting passes, so we cannot properly internally cache the value,
368+
// and we instead could use the LayoutInformation.GetLayoutSlot(root).
369+
//
370+
// The issue is that unlike UWP which will ends by requesting an UpdateLayout with the right window bounds,
371+
// Uno instead exclusively relies on measure/arrange invalidation.
372+
// So if we invoke the `UpdateLayout()` **before** the tree has been measured at least once
373+
// (which is the case when using a MUX.NavigationView in the "MainPage" on iOS as OnApplyTemplate is invoked too early),
374+
// then the whole tree will be measured at the last known value which is 0x0 and will never be invalidated.
375+
//
376+
// To avoid this we are instead using the Window Bounds as anyway they are the same as the root's slot.
377+
var bounds = Windows.UI.Xaml.Window.Current.Bounds;
378+
365379
#if __MACOS__ || __IOS__ // IsMeasureDirty and IsArrangeDirty are not available on iOS / macOS
366-
root.Measure(LayoutInformation.GetLayoutSlot(root).Size);
367-
root.Arrange(LayoutInformation.GetLayoutSlot(root));
380+
root.Measure(bounds.Size);
381+
root.Arrange(bounds);
368382
#elif __ANDROID__
369383
for (var i = 0; i < MaxLayoutIterations; i++)
370384
{
371385
// On Android, Measure and arrange are the same
372386
if (root.IsMeasureDirty)
373387
{
374-
root.Measure(LayoutInformation.GetLayoutSlot(root).Size);
375-
root.Arrange(LayoutInformation.GetLayoutSlot(root));
388+
root.Measure(bounds.Size);
389+
root.Arrange(bounds);
376390
}
377391
else
378392
{
@@ -384,11 +398,11 @@ public void UpdateLayout()
384398
{
385399
if (root.IsMeasureDirty)
386400
{
387-
root.Measure(LayoutInformation.GetLayoutSlot(root).Size);
401+
root.Measure(bounds.Size);
388402
}
389403
else if (root.IsArrangeDirty)
390404
{
391-
root.Arrange(LayoutInformation.GetLayoutSlot(root));
405+
root.Arrange(bounds);
392406
}
393407
else
394408
{

0 commit comments

Comments
 (0)