ViewPager: avoid smooth scrolling large distances

Change-Id: Id99152c8f10aab1a93679e6559e446fb4135070c
This commit is contained in:
SpiritCroc 2021-12-23 14:54:46 +01:00
parent e6a7b4aa5f
commit 2e3e233d5d

View File

@ -65,6 +65,7 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.internal.crypto.model.rest.DeviceInfo
import timber.log.Timber
import javax.inject.Inject
import kotlin.math.abs
class HomeDetailFragment @Inject constructor(
private val avatarRenderer: AvatarRenderer,
@ -542,7 +543,10 @@ class HomeDetailFragment @Inject constructor(
if (selectedIndex != views.roomListContainerPager.currentItem) {
// post() mitigates a case where we could end up in an endless loop circling around the same few spaces
views.roomListContainerPager.post {
views.roomListContainerPager.currentItem = selectedIndex
// Do not smooth scroll large distances to avoid loading unnecessary many room lists
val diff = selectedIndex - views.roomListContainerPager.currentItem
val smoothScroll = abs(diff) <= 1
views.roomListContainerPager.setCurrentItem(selectedIndex, smoothScroll)
}
}
return