calculator: preview full navigation chrome in store screenshots
- Commit
12ced4c5a4003d01cb7fa985c6cf29aa46eb690f- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-25 19:37 UTC (1 month ago)
- Parents
a61f94f
Diff
calculator/src/screenshotTest/kotlin/com/vayunmathur/calculator/ui/MetadataPreviews.kt
diff --git a/calculator/src/screenshotTest/kotlin/com/vayunmathur/calculator/ui/MetadataPreviews.kt b/calculator/src/screenshotTest/kotlin/com/vayunmathur/calculator/ui/MetadataPreviews.ktindex ddf8f76843..d6e6a586a6 100644--- a/calculator/src/screenshotTest/kotlin/com/vayunmathur/calculator/ui/MetadataPreviews.kt+++ b/calculator/src/screenshotTest/kotlin/com/vayunmathur/calculator/ui/MetadataPreviews.kt@@ -1,8 +1,17 @@ package com.vayunmathur.calculator.ui +import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxHeight+import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable+import androidx.compose.runtime.CompositionLocalProvider+import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview+import androidx.navigationevent.compose.LocalNavigationEventDispatcherOwner+import androidx.navigationevent.compose.rememberNavigationEventDispatcherOwner import com.android.tools.screenshot.PreviewTest+import com.vayunmathur.calculator.Route import com.vayunmathur.calculator.util.AngleMode import com.vayunmathur.calculator.util.CalculatorActions import com.vayunmathur.calculator.util.CalculatorUiState@@ -19,6 +28,19 @@ import com.vayunmathur.calculator.util.UnitConverterActions import com.vayunmathur.calculator.util.UnitConverterUiState import com.vayunmathur.calculator.util.UnitRegistry import com.vayunmathur.library.ui.DynamicTheme+import com.vayunmathur.library.ui.IconCalculate+import com.vayunmathur.library.ui.IconFunctions+import com.vayunmathur.library.ui.IconRuler+import com.vayunmathur.library.ui.NavigationRail+import com.vayunmathur.library.ui.NavigationRailItem+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.isCompactHeight+import com.vayunmathur.library.ui.isExpandedWidth+import com.vayunmathur.library.util.BottomBarItem+import com.vayunmathur.library.util.BottomNavBar+import com.vayunmathur.library.util.MainNavigation+import com.vayunmathur.library.util.SiblingPage+import com.vayunmathur.library.util.rememberNavBackStack /** Phone-shaped, roughly 1080x2340 at xxhdpi — comfortably above the F-Droid minimum. */ private const val PHONE = "spec:width=411dp,height=891dp,dpi=420"@@ -55,6 +77,11 @@ private const val EXPANDED = "spec:width=1280dp,height=800dp,dpi=240" * JUnit tests and needs a real class to attach them to — top-level functions land in a * synthetic `…Kt` facade and are silently skipped, which surfaces as "did not discover * any tests".+ * - Previews render through [ChromePreview], not bare screens: the bottom bar and+ * navigation rail live in the app's `Navigation`, above the pages, so a bare+ * `CalculatorScreen` shot would miss the chrome users actually see. The chrome+ * here is the real component (`BottomNavBar`, `NavigationRail`) with the app's+ * real tab list — only the selected tab is literal. * * Rendering goes through the app's real [DynamicTheme] with `darkTheme = true`, matching * the `cmd uimode night yes` the old on-device generator used. Note that Material You@@ -67,98 +94,178 @@ class MetadataPreviews { @Preview(name = "1-keypad", device = PHONE, group = "phone", showSystemUi = true) @Composable fun Preview1Keypad() {- DynamicTheme(darkTheme = true) {- CalculatorScreen(- state = CalculatorUiState(- input = "sin(45) + 2^10",- preview = "1024.707",- memory = 12.5,- angleMode = AngleMode.DEGREES,- ),- actions = CalculatorActions.Noop,- )- }+ ChromePreview(Route.Calculator) } @PreviewTest @Preview(name = "2-graph", device = PHONE, group = "phone", showSystemUi = true) @Composable fun Preview2Graph() {- val colors = GraphTabColors- DynamicTheme(darkTheme = true) {- GraphScreen(- state = GraphUiState(- functions = listOf(- GraphFunction(id = 0, text = "sin(x)", color = colors[0]),- GraphFunction(id = 1, text = "x^2/8 - 2", color = colors[1]),- GraphFunction(id = 2, text = "cos(x)/2", color = colors[2], enabled = false),- ),- markers = listOf(- GraphMarker(GraphPoint(0.0, 0.0), FeatureKind.INTERSECTION, listOf(0L, 1L)),- GraphMarker(GraphPoint(-1.571, -1.0), FeatureKind.MINIMUM, listOf(0L)),- ),- angleMode = AngleMode.RADIANS,- viewport = GraphViewport(centerX = 0.0, centerY = 0.0, scale = 42.0),- ),- actions = GraphActions.Noop,- )- }+ ChromePreview(Route.Graph) } @PreviewTest @Preview(name = "3-history", device = PHONE, group = "phone", showSystemUi = true) @Composable fun Preview3History() {- DynamicTheme(darkTheme = true) {- CalculatorScreen(- state = CalculatorUiState(- input = "12!",- preview = "479001600",- angleMode = AngleMode.RADIANS,- history = listOf(- HistoryEntry("sin(45) + 2^10", "1024.707"),- HistoryEntry("nCr(52,5)", "2598960"),- HistoryEntry("|-17.5| * pi", "54.978"),- HistoryEntry("log(2,4096)", "12"),- ),- ),- actions = CalculatorActions.Noop,- )- }+ ChromePreview(Route.Calculator, showHistory = true) } @PreviewTest @Preview(name = "4-units", device = PHONE, group = "phone", showSystemUi = true) @Composable fun Preview4Units() {- DynamicTheme(darkTheme = true) {- UnitConverterScreen(- state = UnitConverterUiState(- categories = UnitRegistry.categories,- selectedCategoryIndex = 3, // Temperature- fromToken = "degC",- toToken = "degF",- inputText = "100",- outputText = "212",- ),- actions = UnitConverterActions.Noop,- )- }+ ChromePreview(Route.Units) } @PreviewTest @Preview(name = "5-keypad-expanded", device = EXPANDED, group = "large-tablet", showSystemUi = true) @Composable fun Preview5KeypadExpanded() {- DynamicTheme(darkTheme = true) {- CalculatorScreen(- state = CalculatorUiState(- input = "sin(45) + 2^10",- preview = "1024.707",- angleMode = AngleMode.DEGREES,- ),- actions = CalculatorActions.Noop,- )+ ChromePreview(Route.Calculator)+ }+}++/**+ * One tab's screen content, factored out of the previews so [ChromePreview] can+ * host every destination behind the real navigation chrome.+ */+@Composable+private fun KeypadContent() {+ CalculatorScreen(+ state = CalculatorUiState(+ input = "sin(45) + 2^10",+ preview = "1024.707",+ memory = 12.5,+ angleMode = AngleMode.DEGREES,+ ),+ actions = CalculatorActions.Noop,+ )+}++@Composable+private fun HistoryContent() {+ CalculatorScreen(+ state = CalculatorUiState(+ input = "12!",+ preview = "479001600",+ angleMode = AngleMode.RADIANS,+ history = listOf(+ HistoryEntry("sin(45) + 2^10", "1024.707"),+ HistoryEntry("nCr(52,5)", "2598960"),+ HistoryEntry("|-17.5| * pi", "54.978"),+ HistoryEntry("log(2,4096)", "12"),+ ),+ ),+ actions = CalculatorActions.Noop,+ )+}++@Composable+private fun GraphContent() {+ val colors = GraphTabColors+ GraphScreen(+ state = GraphUiState(+ functions = listOf(+ GraphFunction(id = 0, text = "sin(x)", color = colors[0]),+ GraphFunction(id = 1, text = "x^2/8 - 2", color = colors[1]),+ GraphFunction(id = 2, text = "cos(x)/2", color = colors[2], enabled = false),+ ),+ markers = listOf(+ GraphMarker(GraphPoint(0.0, 0.0), FeatureKind.INTERSECTION, listOf(0L, 1L)),+ GraphMarker(GraphPoint(-1.571, -1.0), FeatureKind.MINIMUM, listOf(0L)),+ ),+ angleMode = AngleMode.RADIANS,+ viewport = GraphViewport(centerX = 0.0, centerY = 0.0, scale = 42.0),+ ),+ actions = GraphActions.Noop,+ )+}++@Composable+private fun UnitsContent() {+ UnitConverterScreen(+ state = UnitConverterUiState(+ categories = UnitRegistry.categories,+ selectedCategoryIndex = 3, // Temperature+ fromToken = "degC",+ toToken = "degF",+ inputText = "100",+ outputText = "212",+ ),+ actions = UnitConverterActions.Noop,+ )+}++/**+ * The app's real navigation chrome around preview screen content: the same tab+ * list, the same rail-vs-bottom-bar branch, the same [MainNavigation] host as+ * `Navigation` in MainActivity — with a literal back stack standing in for the+ * selected tab, since previews have no ViewModel to drive one.+ *+ * [showHistory] selects the history variant of the keypad tab (Preview3); the+ * selected tab always matches the shown screen.+ */+@Composable+private fun ChromePreview(route: Route, showHistory: Boolean = false) {+ DynamicTheme(darkTheme = true) {+ // NavDisplay requires a NavigationEventDispatcherOwner, which an Activity+ // normally provides — Layoutlib has no Activity, so previews supply a+ // root dispatcher explicitly (null parent).+ CompositionLocalProvider(+ LocalNavigationEventDispatcherOwner provides rememberNavigationEventDispatcherOwner(+ parent = null,+ ),+ ) {+ ChromePreviewContent(route, showHistory)+ }+ }+}++@Composable+private fun ChromePreviewContent(route: Route, showHistory: Boolean = false) {+ val backStack = rememberNavBackStack(route)+ val current = backStack.last()+ val tabs = listOf(+ BottomBarItem("Calculator", Route.Calculator) { IconCalculate() },+ BottomBarItem("Graph", Route.Graph) { IconFunctions() },+ BottomBarItem("Units", Route.Units) { IconRuler() },+ )+ val entries: @Composable () -> Unit = {+ when (current) {+ Route.Calculator -> if (showHistory) HistoryContent() else KeypadContent()+ Route.Graph -> GraphContent()+ Route.Units -> UnitsContent()+ }+ }+ if (isExpandedWidth() || isCompactHeight()) {+ Row(Modifier.fillMaxSize()) {+ NavigationRail(Modifier.fillMaxHeight()) {+ tabs.forEach { tab ->+ NavigationRailItem(+ selected = current == tab.route,+ onClick = {},+ icon = tab.icon,+ label = { Text(tab.name) },+ )+ }+ }+ Box(Modifier.weight(1f).fillMaxHeight()) {+ MainNavigation(backStack) {+ entry<Route.Calculator>(metadata = SiblingPage()) { entries() }+ entry<Route.Graph>(metadata = SiblingPage()) { entries() }+ entry<Route.Units>(metadata = SiblingPage()) { entries() }+ }+ }+ }+ } else {+ MainNavigation(+ backStack,+ bottomBar = { BottomNavBar(backStack, tabs, current) },+ ) {+ entry<Route.Calculator>(metadata = SiblingPage()) { entries() }+ entry<Route.Graph>(metadata = SiblingPage()) { entries() }+ entry<Route.Units>(metadata = SiblingPage()) { entries() } } } }
metadata_data/photos/calculator/large-tablet/1.png
diff --git a/metadata_data/photos/calculator/large-tablet/1.png b/metadata_data/photos/calculator/large-tablet/1.pngindex 7b647c6393..1339281408 100644Binary files a/metadata_data/photos/calculator/large-tablet/1.png and b/metadata_data/photos/calculator/large-tablet/1.png differ
metadata_data/photos/calculator/phone/1.png
diff --git a/metadata_data/photos/calculator/phone/1.png b/metadata_data/photos/calculator/phone/1.pngindex af6d14de95..d11b1bf5c2 100644Binary files a/metadata_data/photos/calculator/phone/1.png and b/metadata_data/photos/calculator/phone/1.png differ
metadata_data/photos/calculator/phone/2.png
diff --git a/metadata_data/photos/calculator/phone/2.png b/metadata_data/photos/calculator/phone/2.pngindex 07310b2d28..71c819e3e7 100644Binary files a/metadata_data/photos/calculator/phone/2.png and b/metadata_data/photos/calculator/phone/2.png differ
metadata_data/photos/calculator/phone/3.png
diff --git a/metadata_data/photos/calculator/phone/3.png b/metadata_data/photos/calculator/phone/3.pngindex 770ee46f3e..62ec589b16 100644Binary files a/metadata_data/photos/calculator/phone/3.png and b/metadata_data/photos/calculator/phone/3.png differ
metadata_data/photos/calculator/phone/4.png
diff --git a/metadata_data/photos/calculator/phone/4.png b/metadata_data/photos/calculator/phone/4.pngindex 5a4263f190..15c31a9aad 100644Binary files a/metadata_data/photos/calculator/phone/4.png and b/metadata_data/photos/calculator/phone/4.png differ