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

[Android] CollectionView Header/Footer/EmptyView issues when adding/removing items. #24830

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -580,6 +581,7 @@ internal void UpdateEmptyViewVisibility()
}
else if (!showEmptyView && currentAdapter != ItemsViewAdapter)
{
GetRecycledViewPool().Clear();
SwapAdapter(ItemsViewAdapter, true);
UpdateLayoutManager();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down