Skip to content

Commit

Permalink
Fix choppy scrolling and scroll to start
Browse files Browse the repository at this point in the history
  • Loading branch information
adhiamboperes committed Feb 20, 2025
1 parent 7a250bd commit 7c76a2c
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class ProfileChooserFragmentPresenter @Inject constructor(

profilesListLandscape?.viewTreeObserver?.addOnGlobalLayoutListener {
val landscapeList = profilesListLandscape as RecyclerView

if (landscapeList.shouldShowScrollArrows()) {
profileListScrollLeft?.visibility = View.VISIBLE
profileListScrollRight?.visibility = View.VISIBLE
Expand Down Expand Up @@ -163,7 +164,8 @@ class ProfileChooserFragmentPresenter @Inject constructor(
val lastVisiblePosition = layoutManager.findLastVisibleItemPosition()

return if (firstVisiblePosition == RecyclerView.NO_POSITION ||
lastVisiblePosition == RecyclerView.NO_POSITION) {
lastVisiblePosition == RecyclerView.NO_POSITION
) {
0 // No visible items
} else {
lastVisiblePosition - firstVisiblePosition + 1
Expand Down Expand Up @@ -193,10 +195,10 @@ class ProfileChooserFragmentPresenter @Inject constructor(

// Adjust offset based on layout direction and intent.
val offset = when {
scrollLeftInRtl -> scrollableWidth - scrollDistance
scrollLeftInRtl -> scrollableWidth / 2 - scrollDistance
scrollRightInRtl -> scrollDistance - scrollableWidth / 2
scrollLeftInLtr -> scrollDistance - scrollableWidth / 2
scrollRightInLtr -> scrollableWidth - scrollDistance
scrollRightInLtr -> scrollableWidth / 2 - scrollDistance
else -> 0 // Fallback, though this shouldn't occur.
}

Expand Down

0 comments on commit 7c76a2c

Please sign in to comment.