Trigger InvalidateMeasure event on CollectionView when content size changes on iOS (#24647)
This commit is contained in:
Родитель
277ce9fa5b
Коммит
45a1666640
|
@ -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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче