A Microsoft framework for building cross-platform mobile apps using .NET and C# with native performance and user interfaces.
SmoothScrollToPosition Scrolls Wrong Amount From Partially Visible Items
I have a SmoothScroller that inherits from LinearSmoothScroller, and I override CalculateDtToFit as follows:
public override int CalculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd, int snapPreference)
{
int height = viewEnd - viewStart;
int result;
if (((MainActivity)Xamarin.Essentials.Platform.CurrentActivity).rvPlayerNamesInput.GetAdapter().ItemCount == 1)
{ result = base.CalculateDtToFit(viewStart, viewEnd, boxStart, boxEnd, LinearSmoothScroller.SnapToEnd); }
else if (this.TargetPosition == 0)
{ result = base.CalculateDtToFit(viewStart, viewEnd + height, boxStart, boxEnd, LinearSmoothScroller.SnapToEnd); }
else if (this.TargetPosition == ((MainActivity)Xamarin.Essentials.Platform.CurrentActivity).rvPlayerNamesInput.GetAdapter().ItemCount - 1)
{ result = base.CalculateDtToFit(viewStart - height, viewEnd, boxStart, boxEnd, LinearSmoothScroller.SnapToEnd); }
else
{ result = base.CalculateDtToFit(viewStart - height, viewEnd + height, boxStart, boxEnd, LinearSmoothScroller.SnapToEnd); }
return result;
}
When I call SmoothScrollToPosition(x) to scroll to a RecyclerView item that is completely visible, everything works exactly as expected. However, for items that are only partially visible (not completely offscreen, just not 100% within view), it does not. What it looks like it is doing for the partially visible items is using base.CalculateDtToFit with the original values & SnapToAny rather than what I have in the code above. However, I have confirmed that the code above is being called & returning the desired values (for both completely & partially visible items), yet it only scrolls the returned value for completely visible items (partially visible items do scroll, but not by the amount returned here). This override is always called & returns the desired value, so why does it not always use the returned value?