From c7bab22dc56be4601e63b54ced997a58aa1844d7 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Sat, 26 Sep 2026 19:33:35 +0000 Subject: [PATCH] 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. --- .../main/kotlin/com/subtracks/ui/library/LibraryScreen.kt | 1 + app/src/test/kotlin/com/subtracks/ui/LibraryScreenTest.kt | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/subtracks/ui/library/LibraryScreen.kt b/app/src/main/kotlin/com/subtracks/ui/library/LibraryScreen.kt index 551af84f..9c4934ed 100644 --- a/app/src/main/kotlin/com/subtracks/ui/library/LibraryScreen.kt +++ b/app/src/main/kotlin/com/subtracks/ui/library/LibraryScreen.kt @@ -335,6 +335,7 @@ fun LibraryScreen( HorizontalPager( state = pagerState, modifier = Modifier.fillMaxSize(), + beyondViewportPageCount = 1, ) { page -> val pageTab = LibraryTab.entries[page] val resetKey = resetKeys[pageTab] diff --git a/app/src/test/kotlin/com/subtracks/ui/LibraryScreenTest.kt b/app/src/test/kotlin/com/subtracks/ui/LibraryScreenTest.kt index 2e5ed1d5..1fa99357 100644 --- a/app/src/test/kotlin/com/subtracks/ui/LibraryScreenTest.kt +++ b/app/src/test/kotlin/com/subtracks/ui/LibraryScreenTest.kt @@ -32,7 +32,6 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf import org.junit.Assert.assertEquals -import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Rule import org.junit.Test @@ -112,7 +111,7 @@ class LibraryScreenTest { } @Test - fun onlyTheVisibleTabCollectsItsPagingFlow() { + fun theVisibleTabAndItsNeighbourCollectTheirPagingFlows() { val collected = CopyOnWriteArrayList() val albums = flow> { @@ -147,10 +146,10 @@ class LibraryScreenTest { } } - composeRule.waitUntil(timeoutMillis = 5_000) { collected.isNotEmpty() } + composeRule.waitUntil(timeoutMillis = 5_000) { collected.contains("artists") } composeRule.waitForIdle() - assertEquals(listOf("albums"), collected.toList()) + assertEquals(listOf("albums", "artists"), collected.toList()) } @Test @@ -204,7 +203,6 @@ class LibraryScreenTest { 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")) - assertFalse("inactive tabs should not collect their flows", collected.contains("playlists")) } @Test