Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue32221.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System.Collections.ObjectModel;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 32221, "[iOS] ScrollView does not resize when children are removed from StackLayout at runtime", PlatformAffected.iOS)]

public class Issue32221 : ContentPage
{
int labelCount = 3;
StackLayout labelStack;

public Issue32221()
{
// Create the label stack
labelStack = new StackLayout
{
BackgroundColor = Colors.Beige,
Spacing = 10
};

// Add initial labels
for (int i = 1; i <= labelCount; i++)
{
labelStack.Children.Add(new Label
{
Text = $"Label {i}",
FontSize = 18,
Padding = new Thickness(10)
});
}

// Create ScrollView to hold the label stack
var scrollView = new ScrollView
{
Content = labelStack
};

// Create buttons
var addButton = new Button
{
Text = "Add Label",
AutomationId = "AddLabelButton"
};
addButton.Clicked += OnAddLabelClicked;

var removeButton = new Button
{
Text = "Remove Label",
AutomationId = "RemoveLabelButton"
};
removeButton.Clicked += OnRemoveLabelClicked;

// Create the main layout
var mainLayout = new VerticalStackLayout
{
Padding = 20,
Children = { scrollView, addButton, removeButton }
};

// Set the page content
Content = mainLayout;
}

void OnAddLabelClicked(object sender, EventArgs e)
{
labelCount++;
labelStack.Children.Add(new Label
{
Text = $"Label {labelCount}",
FontSize = 18,
Padding = new Thickness(10)
});
}

void OnRemoveLabelClicked(object sender, EventArgs e)
{
if (labelStack.Children.Count > 0)
{
labelStack.Children.RemoveAt(labelStack.Children.Count - 1);
labelCount--;
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;
public class Issue32221 : _IssuesUITest
{
public Issue32221(TestDevice device) : base(device) { }

public override string Issue => "[iOS] ScrollView does not resize when children are removed from StackLayout at runtime";
[Test]
[Category(UITestCategories.ScrollView)]
public void VerifyScrollViewHeightWhenRemoveChildAtRuntime()
{
App.WaitForElement("AddLabelButton");
App.Tap("AddLabelButton");
App.Tap("RemoveLabelButton");
VerifyScreenshot();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending snapshots already available in the latest build.

Image

Could you commit the images?

}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Core/src/Platform/iOS/MauiScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ bool IPlatformMeasureInvalidationController.InvalidateMeasure(bool isPropagating
SetNeedsLayout();
InvalidateConstraintsCache();

return !isPropagating;
return true;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[major] Layout Measure-Arrange — Returning true for every propagated child invalidation makes MauiScrollView stop acting as a layout propagation boundary, so any descendant measure invalidation now bubbles into the ancestor hierarchy even when the ScrollView's own size is externally constrained. MauiView only continues propagation until fixed constraints, and this ScrollView already has targeted ancestor invalidation when ContentSize actually changes in LayoutSubviews. Please scope propagation to cases where the ScrollView's desired size can actually change, or mirror the fixed-constraints guard, instead of always propagating.

}

/// <summary>
Expand Down
Loading