fix(mobile): fit the Live Activity's elapsed time in the island and on Always On
Merged
CH
12h ago+106+106+012345678901234567890123456789-22-22-01234567890123456789
Bug
Charles's iPhone: the Dynamic Island's compact trailing timer reads "22:…". With the screen off (Always On) it reads "22 hours, 38 minu…".
Root cause
- Lit: #10759 put
Text(timerInterval:)in.frame(maxWidth: 44). Apple's docs for time-driven text say it "becomes horizontally flexible and expands to fill the available width", since a widget is laid out once (Text.init(_:format:), Redaction for Reduced Luminance). So the text took exactly 44 pt. That is narrower than five monospaced digits at the island's default font, so a reading like "22:38:12" was cut off. - Always On: nothing in our view branches on it. SwiftUI itself, "when the text is displayed with reduced luminance and frame rate … removes parts that change more frequently than the frame rate allows". For the timer that means dropping the seconds and spelling the rest out ("22 hours, 38 minutes"), which no slot has room for.
- "22" is hours. Always On's spelled form "22 hours, 38 minutes" can only come from a timer reading 22:38:xx. A turn may run up to a day (
TURN_DEADLINE.CAP_MS), and the service rotates the activity every 7 h 45 m, so the activity keeps standing.
Fix
Every elapsed time in the activity is one ElapsedTime view:
- Lit: Apple's system timer format,
Text(.currentDate, format: .timer(countingUpIn:maxFieldCount:)).- Compact island: 2 fields, which reads "4:05" under an hour (ticking seconds) and "22:38" (hours:minutes) past it. Apple's HIG asks the compact island for "shortened units or less precise data" to fit.
- Rows (expanded, Lock Screen, Watch/CarPlay
.small): 3 fields, "1:22:05".
- Dimmed (
isLuminanceReduced):Text(.durationOffset(to:), format: .time(pattern: .hourMinute)), which reads "0:22" or "22:38". It has no seconds for the system to drop, so it never turns into words. - Width: each reading stands in a hidden template of its widest reading ("00:00", "00:00:00") instead of a point width, so the frame follows the font it's drawn in. A turn runs a day at most, so two hour digits always fit.
- Previews: compact, expanded, and Lock Screen gain a
longRunningstate (22 h 38 m).
Screens
Before/after from the Mac's native build, at 22 minutes and 22 hours, will follow in a comment. The simulator has no Always On, so the dimmed form is shot with its branch forced on.
Tests
No unit tests: the change is SwiftUI layout in the widget, checked by maestro/live-activity.yaml on the Mac. CI on Linux doesn't compile this Swift, so the Mac's native build is its compile check.
🤖 Generated with Claude Code