appstore: tap a screenshot to open a full-screen zoomable viewer (#918)
- Commit
e61e1938d996de3bcaaee8bdd87cabe006048dbb- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-14 14:07 UTC (22 days ago)
- Parents
fd5477e
Issue #918: on an app's page there was no way to see a listing screenshot bigger than the 220dp strip, so text in a screenshot was often unreadable. The strip images were not even clickable. What changed: - Tapping a screenshot in the app page's strip pushes a new Route.Screenshots(appName, urls, index), rendered by the new ScreenshotViewerScreen. The route carries its own URL list instead of reading the selected app back out of the view model, so a restored back stack still has its images. - The viewer is a black, edge-to-edge HorizontalPager over that app's screenshots, starting at the tapped one (index clamped). Each page uses the shared :library:ui zoomGestures (moved out of Photos in the previous commit): pinch-to-zoom around the fingers, double tap to zoom into the tapped point and back, drag to pan. A zoomed page pans first and hands the swipe to the pager at its edge, and snaps back to fit once it is swiped away. - Chrome is a TopAppBarOverlay with an "n / total" counter and a close button; a tap toggles it so it never has to cover the image. System back pops the route as usual. - Insets: pages are laid out inside the scaffold's system-bar padding, so at fit nothing sits under the status/navigation bars in portrait or landscape, on phones or tablets, while the black backdrop runs edge to edge. The overlay bar applies its own status-bar inset. - Accessibility: each strip image is now a button described as "<App> screenshot 2 of 5" with the click label "View full screen"; each viewer page carries the same description. Descriptions sit on the tap target/page rather than the bitmap, because AsyncImage only emits its Image (and its description) once decoded. - Loading shows a spinner and a failed load says so, instead of an empty black page. The viewer loads the same URL model the strip did, so the bitmap normally comes straight from the memory cache. - Strip items are keyed by index+URL; a listing that repeats a URL no longer trips LazyRow's duplicate-key crash. Not changed: the TV detail page (D-pad, no touch) keeps its shelf. The phone details page looks the same at rest, so the store listing screenshots (src/screenshotTest) were not regenerated. Related: #902 (Markdown/HTML descriptions) is separate and untouched. Tests (Robolectric): ScreenshotViewerScreenTest checks the viewer opens at the tapped index, clamps an out-of-range index, swipes to the next screenshot, closes from the button, toggles chrome on tap, and closes when there is nothing to show. AppDetailHeaderRichTest and AppDetailScreenTest check a tap on the Nth screenshot reports index N, and RouteSerializerTest round-trips Route.Screenshots. Verified in the toolchain container: :appstore:lint passes; the new and touched test classes pass (ScreenshotViewerScreenTest 6/6, AppDetailScreenTest 11/11, AppDetailHeaderRichTest 8/8, RouteSerializerTest 2/2). The full :appstore:testDevUnitTest run has 25 failures, all in data/Play/ Accrescent/TV tests that assert a fetch fails offline; the build container has network through a proxy, so those fetches succeed. None of them touch the detail page or the viewer.
Diff
appstore/AGENTS.md
diff --git a/appstore/AGENTS.md b/appstore/AGENTS.mdindex df93329d04..1a7a573ab4 100644--- a/appstore/AGENTS.md+++ b/appstore/AGENTS.md@@ -82,6 +82,7 @@ _Install: ./install appstore (dev by default)._ - com/vayunmathur/appstore/ui/AppDetailPage.kt - com/vayunmathur/appstore/ui/AppDetailHeader.kt - com/vayunmathur/appstore/ui/AppDetailSections.kt+- com/vayunmathur/appstore/ui/ScreenshotViewerScreen.kt — full-screen swipe/zoom screenshot viewer (`Route.Screenshots`, #918) - com/vayunmathur/appstore/ui/AppTile.kt - com/vayunmathur/appstore/ui/AppComponents.kt - com/vayunmathur/appstore/ui/AppMeta.kt
appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt b/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.ktindex c28846b5b2..47933a4319 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt@@ -21,6 +21,7 @@ import com.vayunmathur.appstore.ui.AppDetailPage import com.vayunmathur.appstore.ui.BrowsePage import com.vayunmathur.appstore.ui.HomePage import com.vayunmathur.appstore.ui.LibraryPage+import com.vayunmathur.appstore.ui.ScreenshotViewerScreen import com.vayunmathur.appstore.ui.SearchPage import com.vayunmathur.appstore.ui.SourcesPage import com.vayunmathur.appstore.ui.TrustPage@@ -116,6 +117,13 @@ sealed interface Route : NavKey { @Serializable data object Trust : Route @Serializable data object Detail : Route @Serializable data class Browse(val sectionId: String) : Route++ /**+ * Full-screen screenshot viewer (#918). Carries its own URL list rather than reading the+ * selected app back out of the view model, so a restored back stack still has its images.+ */+ @Serializable+ data class Screenshots(val appName: String, val urls: List<String>, val index: Int) : Route } /**@@ -181,6 +189,20 @@ private fun AppRoot( viewModel.clearSelection() }, onOpenTrust = { backStack.add(Route.Trust) },+ onOpenScreenshot = { index ->+ val app = viewModel.detail.value.app+ if (app != null && app.screenshots.isNotEmpty()) {+ backStack.add(Route.Screenshots(app.name, app.screenshots, index))+ }+ },+ )+ }+ entry<Route.Screenshots> { route ->+ ScreenshotViewerScreen(+ appName = route.appName,+ urls = route.urls,+ initialIndex = route.index,+ onClose = { backStack.pop() }, ) } }
appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailHeader.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailHeader.kt b/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailHeader.ktindex 92f06c3356..f4a38ffabd 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailHeader.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailHeader.kt@@ -1,6 +1,7 @@ package com.vayunmathur.appstore.ui import androidx.compose.foundation.background+import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column@@ -15,6 +16,7 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items+import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue@@ -27,6 +29,9 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.stringResource+import androidx.compose.ui.semantics.Role+import androidx.compose.ui.semantics.contentDescription+import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp@@ -116,20 +121,36 @@ internal fun AppDetailFacts(app: UnifiedApp) { } } -/** Screenshots, at a fixed height so mixed aspect ratios still scroll as one strip. */+/**+ * Screenshots, at a fixed height so mixed aspect ratios still scroll as one strip. Tapping+ * one calls [onOpen] with its index so the full-screen viewer can start there (#918).+ */ @Composable-internal fun AppScreenshotStrip(urls: List<String>) {+internal fun AppScreenshotStrip(+ urls: List<String>,+ appName: String,+ onOpen: (Int) -> Unit = {},+) {+ val openLabel = stringResource(R.string.screenshot_open_full_screen) LazyRow( Modifier.fillMaxWidth(), contentPadding = PaddingValues(horizontal = 16.dp), horizontalArrangement = Arrangement.spacedBy(10.dp), ) {- items(urls, key = { it }) { url ->+ itemsIndexed(urls, key = { index, url -> "$index:$url" }) { index, url -> // The width has to be stated. AsyncImage draws its bitmap with matchParentSize, which // contributes nothing to the measure pass, so an image given only a height resolves to // zero wide and the strip is 220dp of nothing. Start at a phone screenshot's shape and // switch to the real one once the bitmap has been decoded. var ratio by remember(url) { mutableFloatStateOf(PORTRAIT_SCREENSHOT_RATIO) }+ // Described on the tap target, not the bitmap: AsyncImage only emits its Image (and+ // so its description) once decoded, and a still-loading screenshot is still a button.+ val description = stringResource(+ R.string.screenshot_description,+ appName,+ index + 1,+ urls.size,+ ) AsyncImage( model = url, contentDescription = null,@@ -137,7 +158,9 @@ internal fun AppScreenshotStrip(urls: List<String>) { .height(220.dp) .aspectRatio(ratio) .clip(RoundedCornerShape(12.dp))- .background(MaterialTheme.colorScheme.surfaceVariant),+ .background(MaterialTheme.colorScheme.surfaceVariant)+ .clickable(onClickLabel = openLabel, role = Role.Image) { onOpen(index) }+ .semantics { contentDescription = description }, contentScale = ContentScale.Fit, onState = { state -> val size = (state as? AsyncImageState.Success)?.painter?.intrinsicSize
appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailPage.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailPage.kt b/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailPage.ktindex d6cbb4837c..8125678755 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailPage.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailPage.kt@@ -35,9 +35,16 @@ fun AppDetailPage( viewModel: AppStoreViewModel, onBack: () -> Unit, onOpenTrust: () -> Unit = {},+ onOpenScreenshot: (Int) -> Unit = {}, ) { val state by viewModel.detail.collectAsState()- AppDetailScreen(state = state, actions = viewModel, onBack = onBack, onOpenTrust = onOpenTrust)+ AppDetailScreen(+ state = state,+ actions = viewModel,+ onBack = onBack,+ onOpenTrust = onOpenTrust,+ onOpenScreenshot = onOpenScreenshot,+ ) } /**@@ -56,6 +63,8 @@ fun AppDetailScreen( actions: AppDetailActions, onBack: () -> Unit = {}, onOpenTrust: () -> Unit = {},+ /** Opens the full-screen viewer at this index into `app.screenshots` (#918). */+ onOpenScreenshot: (Int) -> Unit = {}, ) { val app = state.app ?: return var showUninstallConfirm by remember { mutableStateOf(false) }@@ -79,7 +88,9 @@ fun AppDetailScreen( ) { AppDetailHeader(state) AppInstallActions(state, actions, onUninstall = { showUninstallConfirm = true })- if (app.screenshots.isNotEmpty()) AppScreenshotStrip(app.screenshots)+ if (app.screenshots.isNotEmpty()) {+ AppScreenshotStrip(app.screenshots, app.name, onOpen = onOpenScreenshot)+ } AppDetailFacts(app) AppDetailDescription(app) AppDetailWhatsNew(app)
appstore/src/main/java/com/vayunmathur/appstore/ui/ScreenshotViewerScreen.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/ui/ScreenshotViewerScreen.kt b/appstore/src/main/java/com/vayunmathur/appstore/ui/ScreenshotViewerScreen.ktnew file mode 100644index 0000000000..2c755fb3f5--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/ScreenshotViewerScreen.kt@@ -0,0 +1,187 @@+package com.vayunmathur.appstore.ui++import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.PaddingValues+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.pager.HorizontalPager+import androidx.compose.foundation.pager.rememberPagerState+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.graphicsLayer+import androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.layout.onSizeChanged+import androidx.compose.ui.platform.testTag+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.semantics.contentDescription+import androidx.compose.ui.semantics.semantics+import androidx.compose.ui.unit.IntSize+import com.vayunmathur.appstore.R+import com.vayunmathur.library.image.compose.AsyncImage+import com.vayunmathur.library.image.compose.AsyncImageState+import com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.CircularProgressIndicator+import com.vayunmathur.library.ui.FadeVisibility+import com.vayunmathur.library.ui.IconClose+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.OverlayAction+import com.vayunmathur.library.ui.R as UiR+import com.vayunmathur.library.ui.Spacing+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TopAppBarOverlay+import com.vayunmathur.library.ui.ZoomState+import com.vayunmathur.library.ui.zoomGestures++/**+ * Full-screen viewer for an app's listing screenshots (#918), opened from the strip on the+ * app page at the screenshot that was tapped.+ *+ * Swipe between screenshots; pinch, double-tap and drag to zoom and pan (the shared+ * [zoomGestures], same as the Photos viewer). A zoomed screenshot pans first and hands the+ * swipe to the pager once it reaches its edge, and it snaps back to fit when it leaves the+ * screen. Tap toggles the close button and counter; system back also closes.+ *+ * Images sit inside the system-bar insets, so nothing is drawn under a cutout or the+ * navigation bar at fit scale in either orientation, while the black backdrop runs edge to+ * edge. The URL is the same model the strip loaded, so the bitmap usually comes straight+ * from the memory cache.+ */+@Composable+fun ScreenshotViewerScreen(+ appName: String,+ urls: List<String>,+ initialIndex: Int,+ onClose: () -> Unit,+) {+ if (urls.isEmpty()) {+ LaunchedEffect(Unit) { onClose() }+ return+ }+ val pagerState = rememberPagerState(initialPage = initialIndex.coerceIn(urls.indices)) { urls.size }+ var chromeVisible by remember { mutableStateOf(true) }+ val closeLabel = stringResource(UiR.string.close)++ AppScaffold(topBar = {}) { padding ->+ Box(+ Modifier+ .fillMaxSize()+ .background(Color.Black)+ ) {+ HorizontalPager(+ state = pagerState,+ modifier = Modifier.fillMaxSize().testTag(VIEWER_PAGER_TAG),+ beyondViewportPageCount = 1,+ ) { page ->+ ZoomableScreenshot(+ url = urls[page],+ description = stringResource(+ R.string.screenshot_description,+ appName,+ page + 1,+ urls.size,+ ),+ isSettledPage = pagerState.settledPage == page,+ padding = padding,+ onTap = { chromeVisible = !chromeVisible },+ )+ }+ FadeVisibility(+ visible = chromeVisible,+ modifier = Modifier.align(Alignment.TopCenter).fillMaxWidth(),+ ) {+ TopAppBarOverlay(+ title = {+ Text(+ stringResource(+ R.string.screenshot_counter,+ pagerState.currentPage + 1,+ urls.size,+ ),+ color = Color.White,+ style = MaterialTheme.typography.labelLarge,+ modifier = Modifier+ .padding(start = Spacing.lg)+ .background(Color.Black.copy(alpha = 0.5f), RoundedCornerShape(Spacing.lg))+ .padding(horizontal = Spacing.md, vertical = Spacing.xs),+ )+ },+ actions = listOf(OverlayAction({ IconClose() }, closeLabel, onClose)),+ )+ }+ }+ }+}++/** One page: the screenshot fitted inside the insets, with its own zoom. */+@Composable+private fun ZoomableScreenshot(+ url: String,+ description: String,+ isSettledPage: Boolean,+ padding: PaddingValues,+ onTap: () -> Unit,+) {+ val zoom = remember { mutableStateOf(ZoomState()) }+ var size by remember { mutableStateOf(IntSize.Zero) }+ var state by remember(url) { mutableStateOf<AsyncImageState>(AsyncImageState.Loading) }+ // A page swiped away comes back at fit, not where it was left zoomed in.+ LaunchedEffect(isSettledPage) {+ if (!isSettledPage) zoom.value = ZoomState()+ }+ Box(+ Modifier+ .fillMaxSize()+ .padding(padding)+ .onSizeChanged { size = it }+ // On the page rather than the bitmap, which only appears once decoded.+ .semantics { contentDescription = description }+ .then(+ zoomGestures(+ zoom = zoom,+ containerSize = { size },+ onZoomChange = { zoom.value = it },+ onTap = { onTap() },+ )+ ),+ contentAlignment = Alignment.Center,+ ) {+ AsyncImage(+ model = url,+ contentDescription = null,+ modifier = Modifier+ .fillMaxSize()+ .graphicsLayer {+ // Read inside the layer block: a pinch re-runs only the transform.+ val z = zoom.value+ scaleX = z.scale+ scaleY = z.scale+ translationX = z.offset.x+ translationY = z.offset.y+ },+ contentScale = ContentScale.Fit,+ onState = { state = it },+ )+ when (state) {+ AsyncImageState.Loading -> CircularProgressIndicator(color = Color.White)+ is AsyncImageState.Error -> Text(+ stringResource(R.string.screenshot_load_failed),+ color = Color.White,+ style = MaterialTheme.typography.bodyMedium,+ )+ else -> Unit+ }+ }+}++/** Test tag on the viewer's pager, for swipe tests. */+internal const val VIEWER_PAGER_TAG = "screenshot-viewer-pager"
appstore/src/main/res/values/strings.xml
diff --git a/appstore/src/main/res/values/strings.xml b/appstore/src/main/res/values/strings.xmlindex fbf1feebad..78eb34da6c 100644--- a/appstore/src/main/res/values/strings.xml+++ b/appstore/src/main/res/values/strings.xml@@ -184,6 +184,11 @@ <string name="detail_install_blocked">Install blocked: %1$s</string> <string name="detail_checked_on_install">Checked on install: %1$s</string> <string name="detail_installed_unverified">Installed unverified: %1$s</string>+ <!-- Screenshot strip on the app page and the full-screen viewer it opens (#918). -->+ <string name="screenshot_description">%1$s screenshot %2$d of %3$d</string>+ <string name="screenshot_open_full_screen">View full screen</string>+ <string name="screenshot_counter">%1$d / %2$d</string>+ <string name="screenshot_load_failed">Couldn\'t load this screenshot</string> <string name="detail_tap_for_trust">Tap to see how this source is checked</string> <!-- Store guarantees: true of every install, from every source. -->
appstore/src/test/java/com/vayunmathur/appstore/RouteSerializerTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/RouteSerializerTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/RouteSerializerTest.ktindex db52d996bc..9741102997 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/RouteSerializerTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/RouteSerializerTest.kt@@ -26,6 +26,14 @@ class RouteSerializerTest { assertEquals(browse, restoredBrowse) assertEquals("editors-choice", assertIs<Route.Browse>(restoredBrowse).sectionId) + val shots: Route = Route.Screenshots("Example", listOf("https://a/1.png", "https://a/2.png"), 1)+ val restoredShots = json.decodeFromString(+ Route.serializer(),+ json.encodeToString(Route.serializer(), shots),+ )+ assertEquals(shots, restoredShots)+ assertEquals(1, assertIs<Route.Screenshots>(restoredShots).index)+ for (route in listOf<Route>(Route.Main, Route.Trust, Route.Detail)) { val restored = json.decodeFromString( Route.serializer(),
appstore/src/test/java/com/vayunmathur/appstore/ui/AppDetailHeaderRichTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/ui/AppDetailHeaderRichTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/ui/AppDetailHeaderRichTest.ktindex fb6df4da69..8cc0ec3507 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/ui/AppDetailHeaderRichTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/ui/AppDetailHeaderRichTest.kt@@ -3,12 +3,14 @@ package com.vayunmathur.appstore.ui import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onAllNodesWithText+import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.util.AppDetailUiState import kotlin.test.Test+import kotlin.test.assertEquals import kotlin.test.assertTrue import org.junit.Rule import org.junit.runner.RunWith@@ -110,8 +112,23 @@ class AppDetailHeaderRichTest { rule.setContent { AppScreenshotStrip( urls = listOf("https://example.org/1.png", "https://example.org/2.png"),+ appName = "Example", ) } rule.waitForIdle() }++ @Test+ fun `tapping a screenshot opens it by index`() {+ var opened: Int? = null+ rule.setContent {+ AppScreenshotStrip(+ urls = listOf("https://example.org/1.png", "https://example.org/2.png"),+ appName = "Example",+ onOpen = { opened = it },+ )+ }+ rule.onNodeWithContentDescription("Example screenshot 2 of 2").performClick()+ assertEquals(1, opened)+ } }
appstore/src/test/java/com/vayunmathur/appstore/ui/AppDetailScreenTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/ui/AppDetailScreenTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/ui/AppDetailScreenTest.ktindex 65012e98bd..19f9eaab2b 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/ui/AppDetailScreenTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/ui/AppDetailScreenTest.kt@@ -4,6 +4,7 @@ import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.hasText import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onAllNodesWithText+import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performScrollTo@@ -171,4 +172,18 @@ class AppDetailScreenTest { rule.waitForIdle() }++ @Test+ fun `tapping a screenshot asks for the viewer at that index`() {+ var opened: Int? = null+ val state = AppDetailUiState(+ app = app().copy(screenshots = listOf("https://example.org/a.png", "https://example.org/b.png")),+ )+ rule.setContent {+ AppDetailScreen(state = state, actions = AppDetailActions.Noop, onOpenScreenshot = { opened = it })+ }+ rule.onNodeWithContentDescription("Example screenshot 1 of 2").performScrollTo()+ rule.onNodeWithContentDescription("Example screenshot 1 of 2").performClick()+ assertEquals(0, opened)+ } }
appstore/src/test/java/com/vayunmathur/appstore/ui/ScreenshotViewerScreenTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/ui/ScreenshotViewerScreenTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/ui/ScreenshotViewerScreenTest.ktnew file mode 100644index 0000000000..2d3da3c6b6--- /dev/null+++ b/appstore/src/test/java/com/vayunmathur/appstore/ui/ScreenshotViewerScreenTest.kt@@ -0,0 +1,106 @@+package com.vayunmathur.appstore.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.click+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithContentDescription+import androidx.compose.ui.test.onNodeWithTag+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.compose.ui.test.performTouchInput+import androidx.compose.ui.test.swipeLeft+import kotlin.test.Test+import kotlin.test.assertEquals+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner++/**+ * Full-screen screenshot viewer (#918): starts at the tapped screenshot, swipes between+ * them, describes each page, and closes from its button. Images never decode here (no+ * network loader in unit tests), which is exactly the case the page-level descriptions+ * exist for.+ */+@RunWith(RobolectricTestRunner::class)+class ScreenshotViewerScreenTest {++ @get:Rule+ val rule = createComposeRule()++ private val urls = listOf(+ "https://example.org/1.png",+ "https://example.org/2.png",+ "https://example.org/3.png",+ )++ private fun show(initialIndex: Int = 0, onClose: () -> Unit = {}) {+ rule.setContent {+ ScreenshotViewerScreen(+ appName = "Example",+ urls = urls,+ initialIndex = initialIndex,+ onClose = onClose,+ )+ }+ }++ @Test+ fun `opens at the tapped screenshot`() {+ show(initialIndex = 1)+ rule.onNodeWithText("2 / 3").assertIsDisplayed()+ rule.onNodeWithContentDescription("Example screenshot 2 of 3").assertIsDisplayed()+ }++ @Test+ fun `out of range index is clamped`() {+ show(initialIndex = 9)+ rule.onNodeWithText("3 / 3").assertIsDisplayed()+ }++ @Test+ fun `swiping moves to the next screenshot`() {+ show(initialIndex = 0)+ rule.onNodeWithTag(VIEWER_PAGER_TAG).performTouchInput { swipeLeft() }+ rule.waitForIdle()+ rule.onNodeWithText("2 / 3").assertIsDisplayed()+ rule.onNodeWithContentDescription("Example screenshot 2 of 3").assertIsDisplayed()+ }++ @Test+ fun `close button closes`() {+ var closed = 0+ show(onClose = { closed++ })+ rule.onNodeWithContentDescription("Close").performClick()+ assertEquals(1, closed)+ }++ @Test+ fun `tap hides and restores the chrome`() {+ show()+ val page = rule.onNodeWithContentDescription("Example screenshot 1 of 3")+ page.performTouchInput { click(center) }+ rule.mainClock.advanceTimeBy(DOUBLE_TAP_WAIT_MS)+ rule.waitForIdle()+ rule.onNodeWithText("1 / 3").assertDoesNotExist()++ page.performTouchInput { click(center) }+ rule.mainClock.advanceTimeBy(DOUBLE_TAP_WAIT_MS)+ rule.waitForIdle()+ rule.onNodeWithText("1 / 3").assertIsDisplayed()+ }++ @Test+ fun `no screenshots closes straight away`() {+ var closed = 0+ rule.setContent {+ ScreenshotViewerScreen(appName = "Example", urls = emptyList(), initialIndex = 0, onClose = { closed++ })+ }+ rule.waitForIdle()+ assertEquals(1, closed)+ }++ private companion object {+ /** Past the double-tap timeout, so a single tap is delivered as one. */+ const val DOUBLE_TAP_WAIT_MS = 1_000L+ }+}