Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
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
Original file line number Diff line number Diff line change
@@ -250,17 +250,17 @@ void InvalidateMeasureIfContentSizeChanged()
{
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;
}

Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
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 @@ public async Task CollectionViewCanSizeToContent(CollectionViewSizingTestCase te

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 @@ await CreateHandlerAndAddToWindow<LayoutHandler>(layout, async handler =>
? containerHeight
: Math.Min(itemsCount * templateHeight, containerHeight);

#if IOS
Copy link
Member

Choose a reason for hiding this comment

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

Should this work on Windows and Android?

If it currently doesn't and should, would it make sense to open an issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd say: it should work on all platforms.
But apparently it only makes an actual difference on iOS (issue author is only talking about such platform).
I can try to make it work on Android, but I'll need some help for the Windows platform.

Copy link
Member

Choose a reason for hiding this comment

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

More just curious if we should log an issue

If this test currently fails for Android/Windows we can just log an issue saying so and link to it. No need to hold this PR up for Android/Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I'll file a new issue then.
(Test is failing there)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done #24672

if (layoutOptions != LayoutOptions.Fill)
{
Assert.Equal(n + 1, measureInvalidatedCount);
}
#endif

if (itemsLayout.Orientation == ItemsLayoutOrientation.Horizontal)
{
Assert.Equal(expectedWidth, collectionView.Width, tolerance);