For #13016 - Only scroll to current page in tab history after the initial layout.
parent
52d4ffdef0
commit
a5e9542a6b
|
@ -34,18 +34,25 @@ class TabHistoryView(
|
||||||
|
|
||||||
private val adapter = TabHistoryAdapter(interactor)
|
private val adapter = TabHistoryAdapter(interactor)
|
||||||
private val layoutManager = object : LinearLayoutManager(containerView.context) {
|
private val layoutManager = object : LinearLayoutManager(containerView.context) {
|
||||||
|
|
||||||
|
private var shouldScrollToSelected = true
|
||||||
|
|
||||||
override fun onLayoutCompleted(state: RecyclerView.State?) {
|
override fun onLayoutCompleted(state: RecyclerView.State?) {
|
||||||
super.onLayoutCompleted(state)
|
super.onLayoutCompleted(state)
|
||||||
currentIndex?.let { index ->
|
currentIndex?.let { index ->
|
||||||
// Force expansion of the dialog, otherwise scrolling to the current history item
|
// Attempt to center the current history item after the first layout is completed,
|
||||||
// won't work when its position is near the bottom of the recyclerview.
|
// but not after subsequent layouts
|
||||||
expandDialog.invoke()
|
if (shouldScrollToSelected) {
|
||||||
// Also, attempt to center the current history item.
|
// Force expansion of the dialog, otherwise scrolling to the current history item
|
||||||
val itemView = tabHistoryRecyclerView.findViewHolderForLayoutPosition(
|
// won't work when its position is near the bottom of the recyclerview.
|
||||||
findFirstCompletelyVisibleItemPosition()
|
expandDialog.invoke()
|
||||||
)?.itemView
|
val itemView = tabHistoryRecyclerView.findViewHolderForLayoutPosition(
|
||||||
val offset = tabHistoryRecyclerView.height / 2 - (itemView?.height ?: 0) / 2
|
findFirstCompletelyVisibleItemPosition()
|
||||||
scrollToPositionWithOffset(index, offset)
|
)?.itemView
|
||||||
|
val offset = tabHistoryRecyclerView.height / 2 - (itemView?.height ?: 0) / 2
|
||||||
|
scrollToPositionWithOffset(index, offset)
|
||||||
|
shouldScrollToSelected = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.apply {
|
}.apply {
|
||||||
|
|
Loading…
Reference in New Issue