Skip to content
Draft
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
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--;
}
}
}
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();
}
}
10 changes: 5 additions & 5 deletions src/Core/src/Platform/iOS/MauiScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ public override void LayoutSubviews()
if (ContentSize != contentSize)
{
ContentSize = contentSize;

// Invalidation stops at `UIScrollViews` for performance reasons,
// but when the content size changes, we need to invalidate the ancestors
// in case the ScrollView is configured to grow/shrink with its content.
this.InvalidateAncestorsMeasures();
}

// Invalidation stops at `UIScrollViews` for performance reasons,
// but when the content size changes, we need to invalidate the ancestors
// in case the ScrollView is configured to grow/shrink with its content.
this.InvalidateAncestorsMeasures();
}

base.LayoutSubviews();
Expand Down
Loading