Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #13016 - Only scroll to current page in tab history after the ini…
Browse files Browse the repository at this point in the history
…tial layout.
  • Loading branch information
person808 authored and liuche committed Aug 12, 2020
1 parent 7286c32 commit b346266
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions app/src/main/java/org/mozilla/fenix/tabhistory/TabHistoryView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,25 @@ class TabHistoryView(

private val adapter = TabHistoryAdapter(interactor)
private val layoutManager = object : LinearLayoutManager(containerView.context) {

private var shouldScrollToSelected = true

override fun onLayoutCompleted(state: RecyclerView.State?) {
super.onLayoutCompleted(state)
currentIndex?.let { index ->
// Force expansion of the dialog, otherwise scrolling to the current history item
// won't work when its position is near the bottom of the recyclerview.
expandDialog.invoke()
// Also, attempt to center the current history item.
val itemView = tabHistoryRecyclerView.findViewHolderForLayoutPosition(
findFirstCompletelyVisibleItemPosition()
)?.itemView
val offset = tabHistoryRecyclerView.height / 2 - (itemView?.height ?: 0) / 2
scrollToPositionWithOffset(index, offset)
// Attempt to center the current history item after the first layout is completed,
// but not after subsequent layouts
if (shouldScrollToSelected) {
// Force expansion of the dialog, otherwise scrolling to the current history item
// won't work when its position is near the bottom of the recyclerview.
expandDialog.invoke()
val itemView = tabHistoryRecyclerView.findViewHolderForLayoutPosition(
findFirstCompletelyVisibleItemPosition()
)?.itemView
val offset = tabHistoryRecyclerView.height / 2 - (itemView?.height ?: 0) / 2
scrollToPositionWithOffset(index, offset)
shouldScrollToSelected = false
}
}
}
}.apply {
Expand Down

0 comments on commit b346266

Please sign in to comment.