fix(chat): prevent timeline prefetch ANRs (#985)
This commit is contained in:
1 parent
ce8fdc45bd
commit
c7d7abf4a1
3 files changed
+60
-1
No files matched your search
+33
@@ -0,0 +1,33 @@
|
||||
package com.m57.hermescontrol.ui.chat.components
|
||||
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.lazy.LazyListLayoutInfo
|
||||
import androidx.compose.foundation.lazy.LazyListPrefetchScope
|
||||
import androidx.compose.foundation.lazy.layout.NestedPrefetchScope
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.junit.Test
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
class ChatTimelinePrefetchStrategyTest {
|
||||
@Test
|
||||
fun strategy_neverSchedulesOffscreenChatItems() {
|
||||
val scope = mockk<LazyListPrefetchScope>(relaxed = true)
|
||||
val layoutInfo = mockk<LazyListLayoutInfo>(relaxed = true)
|
||||
val nestedScope = mockk<NestedPrefetchScope>(relaxed = true)
|
||||
|
||||
with(ChatTimelineNoPrefetchStrategy) {
|
||||
with(scope) {
|
||||
onScroll(delta = 120f, layoutInfo)
|
||||
onVisibleItemsUpdated(layoutInfo)
|
||||
}
|
||||
with(nestedScope) {
|
||||
onNestedPrefetch(firstVisibleItemIndex = 10)
|
||||
}
|
||||
}
|
||||
|
||||
verify(exactly = 0) { scope.schedulePrefetch(any(), any()) }
|
||||
verify(exactly = 0) { nestedScope.schedulePrecomposition(any()) }
|
||||
verify(exactly = 0) { nestedScope.schedulePrecompositionAndPremeasure(any(), any()) }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user