mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 07:29:14 +01:00
preload the neighbouring library tab
beyondViewportPageCount = 1 keeps the next tab's paging flow subscribed, so Artists replays cached data instead of showing a spinner the first time it is opened.
This commit is contained in:
@@ -335,6 +335,7 @@ fun LibraryScreen(
|
|||||||
HorizontalPager(
|
HorizontalPager(
|
||||||
state = pagerState,
|
state = pagerState,
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
beyondViewportPageCount = 1,
|
||||||
) { page ->
|
) { page ->
|
||||||
val pageTab = LibraryTab.entries[page]
|
val pageTab = LibraryTab.entries[page]
|
||||||
val resetKey = resetKeys[pageTab]
|
val resetKey = resetKeys[pageTab]
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertFalse
|
|
||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@@ -112,7 +111,7 @@ class LibraryScreenTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun onlyTheVisibleTabCollectsItsPagingFlow() {
|
fun theVisibleTabAndItsNeighbourCollectTheirPagingFlows() {
|
||||||
val collected = CopyOnWriteArrayList<String>()
|
val collected = CopyOnWriteArrayList<String>()
|
||||||
val albums =
|
val albums =
|
||||||
flow<PagingData<Album>> {
|
flow<PagingData<Album>> {
|
||||||
@@ -147,10 +146,10 @@ class LibraryScreenTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
composeRule.waitUntil(timeoutMillis = 5_000) { collected.isNotEmpty() }
|
composeRule.waitUntil(timeoutMillis = 5_000) { collected.contains("artists") }
|
||||||
composeRule.waitForIdle()
|
composeRule.waitForIdle()
|
||||||
|
|
||||||
assertEquals(listOf("albums"), collected.toList())
|
assertEquals(listOf("albums", "artists"), collected.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -204,7 +203,6 @@ class LibraryScreenTest {
|
|||||||
|
|
||||||
assertTrue("returning to a tab should render its content", collected.contains("albums"))
|
assertTrue("returning to a tab should render its content", collected.contains("albums"))
|
||||||
assertTrue("the tab that was shown should collect its flow", collected.contains("artists"))
|
assertTrue("the tab that was shown should collect its flow", collected.contains("artists"))
|
||||||
assertFalse("inactive tabs should not collect their flows", collected.contains("playlists"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user