Skip to content

Commit c8c724d

Browse files
authored
Fixes footer position not updated on CV1 when clearing all items (#29173)
* Fixes footer position not updated on CV1 when clearing all items * Fix UITest
1 parent 628787f commit c8c724d

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,12 @@ internal virtual void CellDisplayingEndedFromDelegate(UICollectionViewCell cell,
924924
!Equals(itemsSource[indexPath], bindingContext))
925925
{
926926
templatedCell.Unbind();
927+
928+
if (CollectionView is MauiCollectionView collectionView)
929+
{
930+
// When removing a cell, we need to trigger a layout update in order to sync the footer position
931+
collectionView.NeedsCellLayout = true;
932+
}
927933
}
928934
}
929935
}

src/Controls/tests/TestCases.HostApp/Elements/CollectionView/HeaderFooterGalleries/HeaderFooterView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
x:Class=" Maui.Controls.Sample.CollectionViewGalleries.HeaderFooterGalleries.HeaderFooterView">
88
<ContentPage.Content>
99

10-
<CollectionView x:Name="CollectionView" ItemsSource="{Binding Items}">
10+
<CollectionView x:Name="CollectionView" AutomationId="CV" ItemsSource="{Binding Items}">
1111

1212
<CollectionView.Header>
1313

src/Controls/tests/TestCases.HostApp/Elements/CollectionView/HeaderFooterGalleries/HeaderFooterView.xaml.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@ public HeaderFooterViewModel(int count = 50, Func<string, CollectionViewGalleryT
2121
{
2222
}
2323

24-
public ICommand AddCommand => new Command(async () => await AddItemsAsync());
24+
public ICommand AddCommand => new Command(AddItemsAsync);
2525

2626
public ICommand ClearCommand => new Command(() => Items.Clear());
2727

2828
public string HeaderText => "This Is A Header";
2929

3030
public string FooterText => "This Is A Footer";
3131

32-
async Task AddItemsAsync()
32+
void AddItemsAsync()
3333
{
34-
await Task.Delay(TimeSpan.FromSeconds(1));
3534
AddItems(Items, 2);
3635
}
3736
}

src/Controls/tests/TestCases.Shared.Tests/Tests/CollectionView/CollectionViewUITests.HeaderAndFooter.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NUnit.Framework;
2+
using NUnit.Framework.Legacy;
23
using UITest.Appium;
34
using UITest.Core;
45

@@ -31,7 +32,7 @@ public void HeaderFooterStringWorks()
3132
#if IOS || ANDROID
3233
[Test]
3334
[Category(UITestCategories.CollectionView)]
34-
public void HeaderFooterViewWorks()
35+
public async Task HeaderFooterViewWorks()
3536
{
3637
// Navigate to the selection galleries
3738
VisitInitialGallery("Header Footer");
@@ -41,6 +42,20 @@ public void HeaderFooterViewWorks()
4142

4243
App.WaitForElement("This Is A Header");
4344
App.WaitForElement("This Is A Footer");
45+
46+
// Now let's add items until the footer goes out of the screen
47+
// and then remove them all and verify the footer is visible again (#29137)
48+
var i = 5;
49+
while (--i > 0)
50+
{
51+
App.WaitForElement("Add 2 Items").Tap();
52+
App.ScrollDownTo("Add 2 Items", "CV");
53+
}
54+
55+
App.WaitForElement("Clear All Items").Tap();
56+
await Task.Delay(300);
57+
58+
ClassicAssert.IsTrue(App.WaitForElement("This Is A Footer").IsDisplayed());
4459
}
4560

4661
[Test]

0 commit comments

Comments
 (0)