Bug 1824581 - Fix bug causing the XML Tabs Tray to not scroll to the selected tab

(cherry picked from commit 1889bee069cb087199d754b90743d80d8166b1fc)
fenix/120.0
Noah Bond 8 months ago committed by mergify[bot]
parent 474282b386
commit 8de9b50069

@ -12,8 +12,14 @@ import androidx.recyclerview.widget.RecyclerView
fun <VH : RecyclerView.ViewHolder> RecyclerView.Adapter<out VH>.observeFirstInsert(block: () -> Unit) {
val observer = object : RecyclerView.AdapterDataObserver() {
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
block.invoke()
unregisterAdapterDataObserver(this)
// There's a bug where [onItemRangeInserted] is intermittently called with an [itemCount] of zero, causing
// the Tabs Tray to always open scrolled at the top. This check forces [onItemRangeInserted] to wait
// until [itemCount] is non-zero to execute [block] and remove the adapter observer.
// This is a temporary fix until the Compose rewrite is enabled by default, where this bug is not present.
if (itemCount > 0) {
block.invoke()
unregisterAdapterDataObserver(this)
}
}
}
registerAdapterDataObserver(observer)

Loading…
Cancel
Save