diff --git a/src/Controls/src/Core/Handlers/Items/Android/Adapters/AdapterNotifier.cs b/src/Controls/src/Core/Handlers/Items/Android/Adapters/AdapterNotifier.cs index 6ed445bd5e3e..192d10afbb4e 100644 --- a/src/Controls/src/Core/Handlers/Items/Android/Adapters/AdapterNotifier.cs +++ b/src/Controls/src/Core/Handlers/Items/Android/Adapters/AdapterNotifier.cs @@ -29,9 +29,6 @@ public void NotifyItemInserted(IItemsViewSource source, int startIndex) if (IsValidAdapter()) { _adapter.NotifyItemInserted(startIndex); - - var changedCount = _adapter.ItemCount - startIndex; - _adapter.NotifyItemRangeChanged(startIndex, changedCount); } } @@ -40,10 +37,6 @@ public void NotifyItemMoved(IItemsViewSource source, int fromPosition, int toPos if (IsValidAdapter()) { _adapter.NotifyItemMoved(fromPosition, toPosition); - - var minPosition = System.Math.Min(fromPosition, toPosition); - var changedCount = _adapter.ItemCount - minPosition; - _adapter.NotifyItemRangeChanged(minPosition, changedCount); } } @@ -58,9 +51,6 @@ public void NotifyItemRangeInserted(IItemsViewSource source, int startIndex, int if (IsValidAdapter()) { _adapter.NotifyItemRangeInserted(startIndex, count); - - var changedCount = _adapter.ItemCount - startIndex; - _adapter.NotifyItemRangeChanged(startIndex, changedCount); } } @@ -69,9 +59,6 @@ public void NotifyItemRangeRemoved(IItemsViewSource source, int startIndex, int if (IsValidAdapter()) { _adapter.NotifyItemRangeRemoved(startIndex, count); - - var changedCount = _adapter.ItemCount - startIndex; - _adapter.NotifyItemRangeChanged(startIndex, changedCount); } } @@ -80,9 +67,6 @@ public void NotifyItemRemoved(IItemsViewSource source, int startIndex) if (IsValidAdapter()) { _adapter.NotifyItemRemoved(startIndex); - - var changedCount = _adapter.ItemCount - startIndex; - _adapter.NotifyItemRangeChanged(startIndex, changedCount); } } diff --git a/src/Controls/src/Core/Handlers/Items/Android/MauiRecyclerView.cs b/src/Controls/src/Core/Handlers/Items/Android/MauiRecyclerView.cs index c4afc301aa67..9bcc1758eb3e 100644 --- a/src/Controls/src/Core/Handlers/Items/Android/MauiRecyclerView.cs +++ b/src/Controls/src/Core/Handlers/Items/Android/MauiRecyclerView.cs @@ -567,11 +567,12 @@ internal void UpdateEmptyViewVisibility() itemCount++; } - var showEmptyView = ItemsView?.EmptyView != null && ItemsViewAdapter.ItemCount == itemCount; + var showEmptyView = (ItemsView?.EmptyView is not null || ItemsView?.EmptyViewTemplate is not null) && ItemsViewAdapter.ItemCount == itemCount; var currentAdapter = GetAdapter(); if (showEmptyView && currentAdapter != _emptyViewAdapter) { + GetRecycledViewPool().Clear(); SwapAdapter(_emptyViewAdapter, true); // TODO hartez 2018/10/24 17:34:36 If this works, cache this layout manager as _emptyLayoutManager @@ -580,6 +581,7 @@ internal void UpdateEmptyViewVisibility() } else if (!showEmptyView && currentAdapter != ItemsViewAdapter) { + GetRecycledViewPool().Clear(); SwapAdapter(ItemsViewAdapter, true); UpdateLayoutManager(); } diff --git a/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs b/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs index 3e10fd5c2544..6d0feb80116a 100644 --- a/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs +++ b/src/Controls/src/Core/Handlers/Items/iOS/ItemsViewController.cs @@ -567,7 +567,7 @@ protected virtual void HandleFormsElementMeasureInvalidated(VisualElement formsE internal void UpdateView(object view, DataTemplate viewTemplate, ref UIView uiView, ref VisualElement formsElement) { // Is view set on the ItemsView? - if (view == null) + if (view is null && viewTemplate is null) { if (formsElement != null) { diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CollectionViewHeaderBlankWhenLastItemRemoved.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CollectionViewHeaderBlankWhenLastItemRemoved.png new file mode 100644 index 000000000000..f537c8555dd0 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CollectionViewHeaderBlankWhenLastItemRemoved.png differ diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CollectionviewFooterHideswhenDynamicallyAddorRemoveItems.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CollectionviewFooterHideswhenDynamicallyAddorRemoveItems.png new file mode 100644 index 000000000000..e543f83433c2 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CollectionviewFooterHideswhenDynamicallyAddorRemoveItems.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue11896.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue11896.xaml new file mode 100644 index 000000000000..7de4c4225914 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue11896.xaml @@ -0,0 +1,57 @@ + + + + + + +