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..66219acdf3cc 100644 --- a/src/Controls/src/Core/Handlers/Items/Android/MauiRecyclerView.cs +++ b/src/Controls/src/Core/Handlers/Items/Android/MauiRecyclerView.cs @@ -572,6 +572,7 @@ internal void UpdateEmptyViewVisibility() 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/ItemsViewHandler.Android.cs b/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs index ca839407bc84..a3c10b2bd038 100644 --- a/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs +++ b/src/Controls/src/Core/Handlers/Items/ItemsViewHandler.Android.cs @@ -109,8 +109,25 @@ void UpdateEmptyViewSize(double width, double height) if (adapter is EmptyViewAdapter emptyViewAdapter) { + var emptyView = emptyViewAdapter.EmptyView ?? emptyViewAdapter.EmptyViewTemplate; + Size size = Size.Zero; + + IView view = emptyView as IView ?? (emptyView as DataTemplate)?.CreateContent() as IView; + + if (view != null) + { + if (view.Handler == null) + { + TemplateHelpers.GetHandler(view as View, this.MauiContext); + } + + size = view.Measure(double.PositiveInfinity, double.PositiveInfinity); + } + + var measuredHeight = !double.IsInfinity(size.Height) ? Context.ToPixels(size.Height) : height; + emptyViewAdapter.RecyclerViewWidth = width; - emptyViewAdapter.RecyclerViewHeight = height; + emptyViewAdapter.RecyclerViewHeight = measuredHeight > 0 ? measuredHeight : height; } } }