diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyScrollViewHeightWhenRemoveChildAtRuntime.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyScrollViewHeightWhenRemoveChildAtRuntime.png new file mode 100644 index 000000000000..b1b2149eb9be Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifyScrollViewHeightWhenRemoveChildAtRuntime.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue32221.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue32221.cs new file mode 100644 index 000000000000..64476e8bd608 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue32221.cs @@ -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--; + } + } +} diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyScrollViewHeightWhenRemoveChildAtRuntime.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyScrollViewHeightWhenRemoveChildAtRuntime.png new file mode 100644 index 000000000000..4e5f5691dad0 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifyScrollViewHeightWhenRemoveChildAtRuntime.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32221.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32221.cs new file mode 100644 index 000000000000..61eeeee267f3 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32221.cs @@ -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(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyScrollViewHeightWhenRemoveChildAtRuntime.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyScrollViewHeightWhenRemoveChildAtRuntime.png new file mode 100644 index 000000000000..727782a4f968 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/VerifyScrollViewHeightWhenRemoveChildAtRuntime.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/VerifyScrollViewHeightWhenRemoveChildAtRuntime.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/VerifyScrollViewHeightWhenRemoveChildAtRuntime.png new file mode 100644 index 000000000000..3a5705b605a4 Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/VerifyScrollViewHeightWhenRemoveChildAtRuntime.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyScrollViewHeightWhenRemoveChildAtRuntime.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyScrollViewHeightWhenRemoveChildAtRuntime.png new file mode 100644 index 000000000000..e68d6518da1f Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifyScrollViewHeightWhenRemoveChildAtRuntime.png differ diff --git a/src/Core/src/Platform/iOS/MauiScrollView.cs b/src/Core/src/Platform/iOS/MauiScrollView.cs index 5362b2bf6c8d..81609f62cbc1 100644 --- a/src/Core/src/Platform/iOS/MauiScrollView.cs +++ b/src/Core/src/Platform/iOS/MauiScrollView.cs @@ -610,7 +610,7 @@ bool IPlatformMeasureInvalidationController.InvalidateMeasure(bool isPropagating SetNeedsLayout(); InvalidateConstraintsCache(); - return !isPropagating; + return true; } ///