Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Fixed ScrollY when ItemsSource reloaded or row height changed #12053

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 6 additions & 1 deletion Xamarin.Forms.Platform.Android/Renderers/ListViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -609,13 +609,15 @@ public TrackElement(int position)

AView _trackedView;
int _trackedViewPrevPosition;
int _trackedViewPrevHeight;
int _trackedViewPrevTop;

public void SyncState(AbsListView view)
{
if (view.ChildCount > 0)
{
_trackedView = GetChild(view);
_trackedViewPrevHeight = view.Height;
_trackedViewPrevTop = GetY();
_trackedViewPrevPosition = view.GetPositionForView(_trackedView);
}
Expand Down Expand Up @@ -653,7 +655,7 @@ AView GetChild(AbsListView view)
}
int GetY()
{
return _position <= 1 ? _trackedView.Bottom : _trackedView.Top;
return _position <= 1 ? (_trackedView.Bottom - (_trackedView.Height - _trackedViewPrevHeight)) : _trackedView.Top;
}
}

Expand Down Expand Up @@ -710,6 +712,9 @@ public void OnScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun
t.SyncState(view);
}
}

if (!wasTracked)
_contentOffset = 0;
}

public void OnScrollStateChanged(AbsListView view, ScrollState scrollState)
Expand Down