Skip to content

Commit d999d56

Browse files
softeiprmarinho
andauthored
[iOS] CollectionView item sizing wrong after refresh (#21736)
* [iOS] CollectionView - ItemsViewLayout: reset EstimatedItemSize and ItemSize when size cache gets cleared Clear * [iOS] Add Test for issue #20443 * [tests] Fix test for #20443 * [iOS] We don t want to mess with EstimatedSize when cells are clearing --------- Co-authored-by: Rui Marinho <[email protected]>
1 parent faf73d3 commit d999d56

File tree

6 files changed

+43
-4
lines changed

6 files changed

+43
-4
lines changed

src/Controls/src/Core/Handlers/Items/iOS/ItemsViewLayout.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ internal virtual bool UpdateConstraints(CGSize size)
113113

114114
ClearCellSizeCache();
115115

116+
EstimatedItemSize = CGSize.Empty;
117+
116118
_currentSize = size;
117119

118120
var newSize = new CGSize(Math.Floor(size.Width), Math.Floor(size.Height));
12.5 KB
Loading

src/Controls/tests/TestCases.HostApp/Issues/Issue20443.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<Grid
2323
HeightRequest="20"
2424
BackgroundColor="Aqua">
25-
<Label Text="20"/>
25+
<Label Text="20" AutomationId="lblSmall"/>
2626
</Grid>
2727
</DataTemplate>
2828
</local:Issue20443TemplateSelector.ItemATemplate>
@@ -31,7 +31,7 @@
3131
<Grid
3232
HeightRequest="100"
3333
BackgroundColor="Pink">
34-
<Label Text="100"/>
34+
<Label Text="100" AutomationId="lblBig"/>
3535
</Grid>
3636
</DataTemplate>
3737
</local:Issue20443TemplateSelector.ItemBTemplate>

src/Controls/tests/TestCases.HostApp/Issues/Issue20443.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Controls.TestCases.HostApp.Issues
99
{
10-
[Issue(IssueTracker.Github, 20443, "CollectionView item gets wrong size after refresh", PlatformAffected.iOS)]
10+
[Issue(IssueTracker.Github, 20443, "CollectionView item sizing wrong after refresh", PlatformAffected.iOS)]
1111

1212
public partial class Issue20443 : ContentPage
1313
{
@@ -39,7 +39,7 @@ public Issue20443ViewModel()
3939
RefreshCommand = new Command(
4040
async () =>
4141
{
42-
await Task.Delay(2000);
42+
await Task.Delay(1000);
4343
IsRefreshing = false;
4444
});
4545

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#if ANDROID || IOS
2+
3+
using NUnit.Framework;
4+
using UITest.Appium;
5+
using UITest.Core;
6+
7+
namespace Microsoft.Maui.TestCases.Tests.Issues
8+
{
9+
public class Issue20443 : _IssuesUITest
10+
{
11+
public override string Issue => "CollectionView item sizing wrong after refresh";
12+
13+
public Issue20443(TestDevice device) : base(device)
14+
{
15+
}
16+
17+
[Test]
18+
[Category(UITestCategories.CollectionView)]
19+
public void RefreshShouldNotChangeSize()
20+
{
21+
_ = App.WaitForElement("lblSmall");
22+
_ = App.WaitForElement("lblBig");
23+
24+
// Try pull to refresh on iOS
25+
App.DragCoordinates(100, 100, 100, 500);
26+
27+
// wait for the fake fresh and the layout to be updated
28+
Task.Delay(3000).Wait();
29+
30+
// Verify the size of the items
31+
VerifyScreenshot();
32+
33+
}
34+
}
35+
}
36+
37+
#endif
24.5 KB
Loading

0 commit comments

Comments
 (0)