Skip to content

Fix RemainingItemsThresholdReachedCommand not firing when CollectionVew has Header and Footer both defined #29618

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Update RecyclerViewScrollListener.cs
  • Loading branch information
SuthiYuvaraj committed May 27, 2025
commit 0230e4bc733ab5276ce3929afb59145df45928d5
Original file line number Diff line number Diff line change
Expand Up @@ -61,36 +61,22 @@ public override void OnScrolled(RecyclerView recyclerView, int dx, int dy)
return;
}

var itemsSourceCount = ItemsViewAdapter.ItemCount;
bool hasHeader = ItemsViewAdapter.ItemsSource.HasHeader;
bool hasFooter = ItemsViewAdapter.ItemsSource.HasFooter;
var itemsSource = ItemsViewAdapter.ItemsSource;
int hasHeader = itemsSource.HasHeader ? 1 : 0;
int hasFooter = itemsSource.HasFooter ? 1 : 0;

int firstDataItemIndex = (hasHeader && hasFooter) ? 1 : 0;
int lastDataItemIndex = itemsSourceCount - firstDataItemIndex;
int lastDataItemIndex = ItemsViewAdapter.ItemCount - hasFooter - hasHeader;

if (Last < firstDataItemIndex || Last > lastDataItemIndex)
if (Last < hasHeader || Last > lastDataItemIndex)
{
return;
}

switch (_itemsView.RemainingItemsThreshold)
bool isThresholdReached = (Last == lastDataItemIndex - 1) || (lastDataItemIndex - 1 - Last <= _itemsView.RemainingItemsThreshold);

if (isThresholdReached)
{
case 0:
{
if (Last == lastDataItemIndex - 1)
{
_itemsView.SendRemainingItemsThresholdReached();
}
break;
}
default:
{
if (lastDataItemIndex - 1 - Last <= _itemsView.RemainingItemsThreshold)
{
_itemsView.SendRemainingItemsThresholdReached();
}
break;
}
_itemsView.SendRemainingItemsThresholdReached();
}
}

Expand Down