Skip to content

Commit b009ee4

Browse files
fix-33333-Changes committed.
1 parent 39ac9f9 commit b009ee4

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/Controls/src/Core/Handlers/Items/Android/RecyclerViewScrollListener.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class RecyclerViewScrollListener<TItemsView, TItemsViewSource> : Recycler
1212
int _horizontalOffset, _verticalOffset;
1313
TItemsView _itemsView;
1414
readonly bool _getCenteredItemOnXAndY = false;
15+
bool _hasCompletedFirstLayout = false;
1516

1617
public RecyclerViewScrollListener(TItemsView itemsView, ItemsViewAdapter<TItemsView, TItemsViewSource> itemsViewAdapter) : this(itemsView, itemsViewAdapter, false)
1718
{
@@ -28,6 +29,8 @@ public RecyclerViewScrollListener(TItemsView itemsView, ItemsViewAdapter<TItemsV
2829
internal void UpdateAdapter(ItemsViewAdapter<TItemsView, TItemsViewSource> itemsViewAdapter)
2930
{
3031
ItemsViewAdapter = itemsViewAdapter;
32+
// Reset flag when adapter changes to handle ItemsSource updates
33+
_hasCompletedFirstLayout = false;
3134
}
3235

3336
public override void OnScrolled(RecyclerView recyclerView, int dx, int dy)
@@ -41,12 +44,17 @@ public override void OnScrolled(RecyclerView recyclerView, int dx, int dy)
4144
_horizontalOffset += dx;
4245
_verticalOffset += dy;
4346

44-
// Prevent the Scrolled event from firing on initial page load while allowing it for ItemsSource changes.
45-
if (!recyclerView.IsLaidOut && dx == 0 && dy == 0)
47+
// Prevent the Scrolled event from firing on the very first layout callback only.
48+
// This is the initial OnScrolled(0,0) call when the view is first laid out.
49+
// After that, layout is marked as complete and all subsequent scroll events are allowed.
50+
if (!_hasCompletedFirstLayout && !recyclerView.IsLaidOut && dx == 0 && dy == 0)
4651
{
4752
return;
4853
}
4954

55+
// Mark that first layout has been processed - all future scrolls should fire events
56+
_hasCompletedFirstLayout = true;
57+
5058
var (First, Center, Last) = GetVisibleItemsIndex(recyclerView);
5159
var itemsViewScrolledEventArgs = new ItemsViewScrolledEventArgs
5260
{

0 commit comments

Comments
 (0)