clock: hide empty stopwatch toolbar before start
- Commit
e2c0b099f746bf3b558bc60c8103a658c8e9b73c- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-05 15:01 UTC (18 hours ago)
- Parents
105d23c
The phone stopwatch always composed its VerticalFloatingToolbar above the play/pause FAB, even before the stopwatch had started. In that state neither of the toolbar's conditional actions exists (lap needs a running stopwatch, reset needs elapsed time), so the toolbar rendered as an empty card with nothing but blank space in it, floating above the play button. Once play was pressed the lap and reset icons appeared inside it. Compose the toolbar only when it has an action to hold (isRunning || countingTime > 0), and let the play/pause FAB stand alone otherwise. Both shapes are anchored by the scaffold at the same bottom-end corner and the toolbar grows upward from the FAB, so the play button does not move when the card appears; no placeholder or reserved empty space remains. A test tag on the toolbar makes the card's absence/presence assertable. The wear stopwatch already shows its lap/reset chips only when they apply, so it needs no change. The stopwatch screenshot preview renders a running stopwatch, so its captures are unchanged. Test-first: the new idle-state test failed against the old always-composed toolbar and passes now. Added compose tests asserting the toolbar card is absent before start (play still shown) and present when running (lap + reset) and when paused with elapsed time (reset). Verified with ./gradlew :clock:lint :clock:lintVitalRelease :clock:testDevUnitTest: lint and lintVitalRelease pass; 292 unit tests run with the single known pre-existing ClockPagesUiTest mainActivityLaunches failure (UnsatisfiedLinkError from SQLite), reproduced identically on a pristine checkout of the base commit 190cdc388, so parity holds.
Diff
clock/src/main/java/com/vayunmathur/clock/ui/StopwatchScreen.kt
diff --git a/clock/src/main/java/com/vayunmathur/clock/ui/StopwatchScreen.kt b/clock/src/main/java/com/vayunmathur/clock/ui/StopwatchScreen.ktindex 8bd37ce86b..0573e03739 100644--- a/clock/src/main/java/com/vayunmathur/clock/ui/StopwatchScreen.kt+++ b/clock/src/main/java/com/vayunmathur/clock/ui/StopwatchScreen.kt@@ -20,6 +20,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.StrokeCap import androidx.compose.ui.graphics.drawscope.Stroke+import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign@@ -45,6 +46,9 @@ import com.vayunmathur.library.ui.VerticalFloatingToolbar import com.vayunmathur.library.ui.isExpandedWidth import kotlin.time.Duration.Companion.seconds +/** Test tag for the stopwatch's lap/reset toolbar card above the play/pause FAB. */+internal const val STOPWATCH_TOOLBAR_TAG = "stopwatchToolbar"+ /** * The stopwatch, with no dependency on the ViewModel so it can be rendered from a * `@Preview` — see `src/screenshotTest`, which is where the store listing images come from.@@ -72,19 +76,33 @@ fun StopwatchScreen( // stopwatch's one control surface rather than stacking as three loose FABs. A toolbar // rather than a FAB menu because lap is timed to whatever the user is measuring and // cannot afford an expand tap first.- VerticalFloatingToolbar(- floatingActionButton = {- FloatingActionButton({ actions.toggleStopwatch() }) {- if(isRunning) IconPause() else IconPlay()- }- },- ) {- if(isRunning) {- IconButton({ actions.addLap() }) { IconTimer() }+ //+ // The toolbar card is only composed when it has an action to hold. Before the+ // stopwatch has started there is neither a lap nor a reset to offer, and an+ // always-composed toolbar renders as an empty card floating above the play+ // button. The play/pause FAB stands alone in that state: the scaffold anchors+ // both shapes at the same bottom-end corner and the toolbar grows upward from+ // the FAB, so the play button does not move when the card appears.+ val hasToolbarActions = isRunning || countingTime > 0.seconds+ val playPauseButton: @Composable () -> Unit = {+ FloatingActionButton({ actions.toggleStopwatch() }) {+ if (isRunning) IconPause() else IconPlay() }- if(countingTime > 0.seconds) {- IconButton({ actions.resetStopwatch() }) { IconRestartAlt() }+ }+ if (hasToolbarActions) {+ VerticalFloatingToolbar(+ modifier = Modifier.testTag(STOPWATCH_TOOLBAR_TAG),+ floatingActionButton = playPauseButton,+ ) {+ if (isRunning) {+ IconButton({ actions.addLap() }) { IconTimer() }+ }+ if (countingTime > 0.seconds) {+ IconButton({ actions.resetStopwatch() }) { IconRestartAlt() }+ } }+ } else {+ playPauseButton() } }, horizontalPadding = 16.dp) { // On expanded widths the dial and the laps sit side by side in fractional
clock/src/test/java/com/vayunmathur/clock/ui/ClockScreensUiTest.kt
diff --git a/clock/src/test/java/com/vayunmathur/clock/ui/ClockScreensUiTest.kt b/clock/src/test/java/com/vayunmathur/clock/ui/ClockScreensUiTest.ktindex 0814e396c0..1847aa791a 100644--- a/clock/src/test/java/com/vayunmathur/clock/ui/ClockScreensUiTest.kt+++ b/clock/src/test/java/com/vayunmathur/clock/ui/ClockScreensUiTest.kt@@ -9,6 +9,7 @@ import androidx.compose.ui.test.hasText import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onAllNodesWithText import androidx.compose.ui.test.onFirst+import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performSemanticsAction@@ -226,4 +227,40 @@ class ClockScreensUiTest { rule.onNodeWithText("0:00", substring = true).assertExists() rule.onNodeWithText("Laps").assertIsDisplayed() }++ @Test+ fun stopwatchNotStartedHasNoToolbarCardAbovePlay() {+ rule.setContent { StopwatchScreen(StopwatchUiState(), StopwatchActions.Noop) }+ // The lap/reset toolbar is a card above the play FAB; with nothing to+ // put in it, it must not be composed at all. Play itself stays.+ rule.onNodeWithTag(STOPWATCH_TOOLBAR_TAG).assertDoesNotExist()+ rule.onNodeWithContentDescription("Play").assertIsDisplayed()+ }++ @Test+ fun stopwatchRunningShowsToolbarCardAbovePause() {+ rule.setContent {+ StopwatchScreen(+ StopwatchUiState(isRunning = true, countingTime = 5.seconds),+ StopwatchActions.Noop,+ )+ }+ rule.onNodeWithTag(STOPWATCH_TOOLBAR_TAG).assertIsDisplayed()+ rule.onNodeWithContentDescription("Timer").assertIsDisplayed()+ rule.onNodeWithContentDescription("Restart").assertIsDisplayed()+ rule.onNodeWithContentDescription("Pause").assertIsDisplayed()+ }++ @Test+ fun stopwatchPausedWithTimeShowsToolbarCard() {+ rule.setContent {+ StopwatchScreen(+ StopwatchUiState(isRunning = false, countingTime = 12.seconds),+ StopwatchActions.Noop,+ )+ }+ rule.onNodeWithTag(STOPWATCH_TOOLBAR_TAG).assertIsDisplayed()+ rule.onNodeWithContentDescription("Restart").assertIsDisplayed()+ rule.onNodeWithContentDescription("Play").assertIsDisplayed()+ } }