Skip to content

Commit

Permalink
fix: Don't skip arrange if the element is measured with zero size
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Sep 19, 2023
1 parent fef77bc commit 4c7390c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,12 @@ public async Task When_Adding_Or_Removing_Child_Should_Re_Measure()
Assert.AreEqual(50, SUT.LastArrangeOverrideReturn.Height);

SUT.Children.Remove(SUT.Children.Single());
#if !__CROSSRUNTIME__
await TestServices.WindowHelper.WaitForRelayouted(SUT); // arrange is skipped (incorrectly) when finalRect is default, which is the case after removing the last child from StackPanel.
await TestServices.WindowHelper.WaitForRelayouted(SUT);
expectedMeasureAndArrangeCount++;
Assert.AreEqual(expectedMeasureAndArrangeCount, SUT.MeasureCount);
Assert.AreEqual(expectedMeasureAndArrangeCount, SUT.ArrangeCount);
Assert.AreEqual(0, SUT.LastMeasureOverrideReturn.Height);
Assert.AreEqual(0, SUT.LastArrangeOverrideReturn.Height);
#endif

SUT.Children.Add(new Border()
{
Expand All @@ -119,14 +117,12 @@ public async Task When_Adding_Or_Removing_Child_Should_Re_Measure()
Assert.AreEqual(50, SUT.LastArrangeOverrideReturn.Height);

SUT.Children.Clear();
#if !__CROSSRUNTIME__
await TestServices.WindowHelper.WaitForRelayouted(SUT); // arrange is skipped (incorrectly) when finalRect is default, which is the case after removing the last child from StackPanel.
await TestServices.WindowHelper.WaitForRelayouted(SUT);
expectedMeasureAndArrangeCount++;
Assert.AreEqual(expectedMeasureAndArrangeCount, SUT.MeasureCount);
Assert.AreEqual(expectedMeasureAndArrangeCount, SUT.ArrangeCount);
Assert.AreEqual(0, SUT.LastMeasureOverrideReturn.Height);
Assert.AreEqual(0, SUT.LastArrangeOverrideReturn.Height);
#endif
}

[TestMethod]
Expand Down
8 changes: 1 addition & 7 deletions src/Uno.UI/UI/Xaml/UIElement.Layout.crossruntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,7 @@ public void Arrange(Rect finalRect)

var firstArrangeDone = IsFirstArrangeDone;

if (Visibility == Visibility.Collapsed
// If the layout is clipped, and the arranged size is empty, we can skip arranging children
// This scenario is particularly important for the Canvas which always sets its desired size
// zero, even after measuring its children.
|| (firstArrangeDone
&& finalRect == default
&& (this is not ICustomClippingElement clipElement || clipElement.AllowClippingToLayoutSlot)))
if (Visibility == Visibility.Collapsed)
{
LayoutInformation.SetLayoutSlot(this, finalRect);
HideVisual();
Expand Down

0 comments on commit 4c7390c

Please sign in to comment.