Trigger InvalidateMeasure event on CollectionView when content size changes on iOS (#24647)

This commit is contained in:
Alberto Aldegheri 2024-09-09 16:31:53 +02:00 коммит произвёл GitHub
Родитель 277ce9fa5b
Коммит 45a1666640
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 16 добавлений и 3 удалений

Просмотреть файл

@ -250,17 +250,17 @@ namespace Microsoft.Maui.Controls.Handlers.Items
{
invalidate = true;
}
if (heightChanged && (contentSize.Value.Height < screenHeight || _previousContentSize.Height < screenHeight))
else if (heightChanged && (contentSize.Value.Height < screenHeight || _previousContentSize.Height < screenHeight))
{
invalidate = true;
}
if (invalidate)
{
(ItemsView as IView)?.InvalidateMeasure();
ItemsView.InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
}
}
_previousContentSize = contentSize.Value;
}

Просмотреть файл

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.Maui.Controls;
@ -375,8 +376,13 @@ Skip = "Fails on iOS/macOS: https://github.com/dotnet/maui/issues/17664"
var frame = collectionView.Frame;
var measureInvalidatedCount = 0;
void OnCollectionViewOnMeasureInvalidated(object s, EventArgs e) => Interlocked.Increment(ref measureInvalidatedCount);
await CreateHandlerAndAddToWindow<LayoutHandler>(layout, async handler =>
{
collectionView.MeasureInvalidated += OnCollectionViewOnMeasureInvalidated;
for (int n = 0; n < itemCounts.Length; n++)
{
int itemsCount = itemCounts[n];
@ -403,6 +409,13 @@ Skip = "Fails on iOS/macOS: https://github.com/dotnet/maui/issues/17664"
? containerHeight
: Math.Min(itemsCount * templateHeight, containerHeight);
#if IOS
if (layoutOptions != LayoutOptions.Fill)
{
Assert.Equal(n + 1, measureInvalidatedCount);
}
#endif
if (itemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)
{
Assert.Equal(expectedWidth, collectionView.Width, tolerance);