Modern Apps git

← Modern-Apps.git

clock: preview tab chrome in store screenshots

Commit
e7aadf767bd991e0d8861b1332b155294b4d3144
Author
vayun-mathur <[email protected]>
When
2026-10-25 19:40 UTC (1 month ago)
Parents
12ced4c

Diff

clock/src/screenshotTest/kotlin/com/vayunmathur/clock/ui/MetadataPreviews.kt
diff --git a/clock/src/screenshotTest/kotlin/com/vayunmathur/clock/ui/MetadataPreviews.kt b/clock/src/screenshotTest/kotlin/com/vayunmathur/clock/ui/MetadataPreviews.ktindex cd7c5107ad..30b3bf3e57 100644--- a/clock/src/screenshotTest/kotlin/com/vayunmathur/clock/ui/MetadataPreviews.kt+++ b/clock/src/screenshotTest/kotlin/com/vayunmathur/clock/ui/MetadataPreviews.kt@@ -1,5 +1,6 @@ package com.vayunmathur.clock.ui +import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.remember@@ -16,6 +17,13 @@ import com.vayunmathur.clock.platform.TimerActions import com.vayunmathur.clock.platform.TimerUiState import com.vayunmathur.clock.platform.WorldClock import com.vayunmathur.library.ui.DynamicTheme+import com.vayunmathur.library.ui.IconAccessTime+import com.vayunmathur.library.ui.IconAlarm+import com.vayunmathur.library.ui.IconHourglass+import com.vayunmathur.library.ui.IconTimer+import com.vayunmathur.library.ui.PagerTab+import com.vayunmathur.library.ui.TabStyle+import com.vayunmathur.library.ui.TabbedPagerScaffold import com.vayunmathur.library.util.LocalNavResultRegistry import com.vayunmathur.library.util.NavResultRegistry import com.vayunmathur.library.util.rememberNavBackStack@@ -50,6 +58,10 @@ private val MORNING = Instant.parse("2026-02-13T17:41:09Z")  * previews must be members of a class rather than top-level functions, and listing order  * comes from the function names — `Preview1…`, `Preview2…`. All three failure modes  * surface as the same unhelpful "did not discover any tests".+ *+ * Previews render through [ChromePreview] — the real [TabbedPagerScaffold] with the+ * app's real tabs — not bare screens, so the bottom bar users see is in the shot.+ * Only the selected tab is literal.  */ class MetadataPreviews { @@ -57,82 +69,119 @@ class MetadataPreviews {     @Preview(name = "1-alarm", device = PHONE, group = "phone", showSystemUi = true)     @Composable     fun Preview1Alarm() {-        DynamicTheme(darkTheme = true) {-            // An alarm card receives its time-picker result through ResultEffect, which-            // reads LocalNavResultRegistry. Outside MainNavigation nothing provides it and-            // composition fails, so hand it a throwaway one — no preview sends a result.-            CompositionLocalProvider(LocalNavResultRegistry provides remember { NavResultRegistry() }) {-                AlarmScreen(-                    backStack = rememberNavBackStack<Route>(Route.Alarm),-                    state = AlarmUiState(-                        alarms = listOf(-                            Alarm(time = LocalTime(6, 30), name = "Wake up", enabled = true, days = WEEKDAYS, id = 1),-                            Alarm(time = LocalTime(8, 0), name = "Gym", enabled = true, days = EVERY_DAY, id = 2),-                            Alarm(time = LocalTime(9, 30), name = "Weekend lie-in", enabled = false, days = WEEKEND, id = 3),-                        ),-                    ),-                    actions = AlarmActions.Noop,-                    initialExpandedAlarmId = 1L,-                )-            }-        }+        ChromePreview(selectedTab = 0)     }      @PreviewTest     @Preview(name = "2-clock", device = PHONE, group = "phone", showSystemUi = true)     @Composable     fun Preview2Clock() {-        DynamicTheme(darkTheme = true) {-            ClockScreen(-                backStack = rememberNavBackStack<Route>(Route.Clock),-                state = ClockUiState(-                    now = { MORNING },-                    zone = TimeZone.of("America/Los_Angeles"),-                    worldClocks = listOf(-                        WorldClock("London", TimeZone.of("Europe/London")),-                        WorldClock("Paris", TimeZone.of("Europe/Paris")),-                        WorldClock("Tokyo", TimeZone.of("Asia/Tokyo")),-                        WorldClock("Sydney", TimeZone.of("Australia/Sydney")),-                    ),-                ),-            )-        }+        ChromePreview(selectedTab = 1)     }      @PreviewTest     @Preview(name = "3-timer", device = PHONE, group = "phone", showSystemUi = true)     @Composable     fun Preview3Timer() {-        DynamicTheme(darkTheme = true) {-            TimerScreen(-                // No timers yet, which is what puts the keypad up; "1000" is the digits-                // for a ten-minute timer, mid-entry.-                state = TimerUiState(now = { MORNING }),-                actions = TimerActions.Noop,-                initialKeypadInput = "1000",-            )-        }+        ChromePreview(selectedTab = 2)     }      @PreviewTest     @Preview(name = "4-stopwatch", device = PHONE, group = "phone", showSystemUi = true)     @Composable     fun Preview4Stopwatch() {-        DynamicTheme(darkTheme = true) {-            StopwatchScreen(-                state = StopwatchUiState(-                    isRunning = true,-                    countingTime = 3.minutes + 42.seconds + 810.milliseconds,-                    // Cumulative, oldest first — the screen derives the splits, and colours-                    // the fastest green and the slowest red.-                    lapTimes = listOf(-                        1.minutes + 12.seconds + 350.milliseconds,-                        2.minutes + 28.seconds + 900.milliseconds,-                        3.minutes + 30.seconds + 120.milliseconds,-                    ),+        ChromePreview(selectedTab = 3)+    }+}++@Composable+private fun AlarmContent() {+    // An alarm card receives its time-picker result through ResultEffect, which+    // reads LocalNavResultRegistry. Outside MainNavigation nothing provides it and+    // composition fails, so hand it a throwaway one — no preview sends a result.+    CompositionLocalProvider(LocalNavResultRegistry provides remember { NavResultRegistry() }) {+        AlarmScreen(+            backStack = rememberNavBackStack<Route>(Route.Alarm),+            state = AlarmUiState(+                alarms = listOf(+                    Alarm(time = LocalTime(6, 30), name = "Wake up", enabled = true, days = WEEKDAYS, id = 1),+                    Alarm(time = LocalTime(8, 0), name = "Gym", enabled = true, days = EVERY_DAY, id = 2),+                    Alarm(time = LocalTime(9, 30), name = "Weekend lie-in", enabled = false, days = WEEKEND, id = 3),                 ),-                actions = StopwatchActions.Noop,-            )-        }+            ),+            actions = AlarmActions.Noop,+            initialExpandedAlarmId = 1L,+        )+    }+}++@Composable+private fun ClockContent() {+    ClockScreen(+        backStack = rememberNavBackStack<Route>(Route.Clock),+        state = ClockUiState(+            now = { MORNING },+            zone = TimeZone.of("America/Los_Angeles"),+            worldClocks = listOf(+                WorldClock("London", TimeZone.of("Europe/London")),+                WorldClock("Paris", TimeZone.of("Europe/Paris")),+                WorldClock("Tokyo", TimeZone.of("Asia/Tokyo")),+                WorldClock("Sydney", TimeZone.of("Australia/Sydney")),+            ),+        ),+    )+}++@Composable+private fun TimerContent() {+    TimerScreen(+        // No timers yet, which is what puts the keypad up; "1000" is the digits+        // for a ten-minute timer, mid-entry.+        state = TimerUiState(now = { MORNING }),+        actions = TimerActions.Noop,+        initialKeypadInput = "1000",+    )+}++@Composable+private fun StopwatchContent() {+    StopwatchScreen(+        state = StopwatchUiState(+            isRunning = true,+            countingTime = 3.minutes + 42.seconds + 810.milliseconds,+            // Cumulative, oldest first — the screen derives the splits, and colours+            // the fastest green and the slowest red.+            lapTimes = listOf(+                1.minutes + 12.seconds + 350.milliseconds,+                2.minutes + 28.seconds + 900.milliseconds,+                3.minutes + 30.seconds + 120.milliseconds,+            ),+        ),+        actions = StopwatchActions.Noop,+    )+}++/**+ * The app's real tab chrome around preview screen content: the same+ * [TabbedPagerScaffold] in [TabStyle.BottomNav] that `ClockTabs` uses, with the+ * same four tabs in the same order — the pager starts on [selectedTab], so the+ * bar highlights the shown screen. Labels/icons are the app's own.+ */+@Composable+private fun ChromePreview(selectedTab: Int) {+    DynamicTheme(darkTheme = true) {+        // TabbedPagerScaffold hosts a HorizontalPager (no NavDisplay), so no+        // dispatcher owner is needed — unlike MainNavigation-based chrome.+        val tabs = listOf(+            PagerTab("Alarm", { IconAlarm() }) { AlarmContent() },+            PagerTab("Clock", { IconAccessTime() }) { ClockContent() },+            PagerTab("Timer", { IconHourglass() }) { TimerContent() },+            PagerTab("Stopwatch", { IconTimer() }) { StopwatchContent() },+        )+        TabbedPagerScaffold(+            tabs = tabs,+            pagerState = rememberPagerState(initialPage = selectedTab, pageCount = { tabs.size }),+            tabStyle = TabStyle.BottomNav,+        )     } }
metadata_data/photos/clock/phone/1.png
diff --git a/metadata_data/photos/clock/phone/1.png b/metadata_data/photos/clock/phone/1.pngindex 5b82bc2e86..40331ed631 100644Binary files a/metadata_data/photos/clock/phone/1.png and b/metadata_data/photos/clock/phone/1.png differ
metadata_data/photos/clock/phone/2.png
diff --git a/metadata_data/photos/clock/phone/2.png b/metadata_data/photos/clock/phone/2.pngindex 4590aa5039..f535786992 100644Binary files a/metadata_data/photos/clock/phone/2.png and b/metadata_data/photos/clock/phone/2.png differ
metadata_data/photos/clock/phone/3.png
diff --git a/metadata_data/photos/clock/phone/3.png b/metadata_data/photos/clock/phone/3.pngindex a840325a06..d35ec218b0 100644Binary files a/metadata_data/photos/clock/phone/3.png and b/metadata_data/photos/clock/phone/3.png differ
metadata_data/photos/clock/phone/4.png
diff --git a/metadata_data/photos/clock/phone/4.png b/metadata_data/photos/clock/phone/4.pngindex 54a1f13d66..e7f1867b0c 100644Binary files a/metadata_data/photos/clock/phone/4.png and b/metadata_data/photos/clock/phone/4.png differ