Live Activity: black background by default + configurable background_color / text_color#4815
Conversation
…d_color Force a stable black Lock Screen background to fix a start-up glitch where the adaptive systemBackground flashed the wrong appearance. Add a background_color field (parsed like notification_icon_color) to override it, and contrast the Lock Screen text with the resolved background's luminance so both the black default and custom colors stay legible. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Found 21 unused localization strings in the codebase. Click to see detailsTo clean up these strings, manually remove them from the |
There was a problem hiding this comment.
Pull request overview
This PR updates the iOS Live Activity (Widget extension) styling to avoid a start-up flash by forcing a stable black Lock Screen background by default, while also introducing a new background_color payload field to allow automations to set a custom Lock Screen background color. It additionally switches foreground/text contrast decisions to be based on the resolved background luminance instead of system light/dark appearance.
Changes:
- Add
background_colortoHALiveActivityAttributes.ContentState(wire keybackground_color) and parse it from Live Activity notification payloads. - Apply the resolved background tint in the Live Activity configuration and choose black/white system action foreground based on background luminance.
- Update tests to cover the new wire key and handler parsing.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/Shared/LiveActivity/LiveActivityContractTests.swift | Extends contract encoding tests to include background_color. |
| Tests/Shared/LiveActivity/HandlerLiveActivityTests.swift | Adds assertions for parsing background_color into content state. |
| Sources/Shared/Notifications/NotificationCommands/HandlerLiveActivity.swift | Parses background_color from the notification payload into Live Activity state. |
| Sources/Shared/LiveActivity/HALiveActivityAttributes.swift | Adds backgroundColor to ContentState and maps it to background_color in Codable keys. |
| Sources/Extensions/Widgets/LiveActivity/HALockScreenView.swift | Switches text/track styling to be based on background luminance; introduces default black background and contrast helper. |
| Sources/Extensions/Widgets/LiveActivity/HALiveActivityConfiguration.swift | Applies background tint from background_color and sets system action foreground color based on luminance. |
An optional text_color overrides the Lock Screen foreground, falling back to the luminance-based auto-contrast when unset. Resolved via a shared HAActivityVisualStyle.foregroundColor(textColor:onBackground:). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4815 +/- ##
=======================================
Coverage ? 45.03%
=======================================
Files ? 278
Lines ? 17006
Branches ? 0
=======================================
Hits ? 7658
Misses ? 9348
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
An empty or whitespace-only background_color/text_color parsed to transparent via UIColor(hex:); normalize it to "unset" so the black/auto-contrast defaults apply. Also drop the "Hex" wording from the field docs since the parser also accepts CSS color names. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Demonstrates background_color and text_color: a Movie Night card with a navy background and amber text. The sample's Start button and generated YAML now carry both fields (Stage gained backgroundColor/textColor). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Live Activities sometimes flashed the wrong background color when starting: the Lock Screen surface used the adaptive
systemBackground, which resolves late/incorrectly as the activity appears. This forces a stable black background by default, removing the glitch.It also adds
background_colorandtext_colornotification fields — parsed with the same rules asnotification_icon_color(CSS names / 3-6-8-digit hex viaUIColor(hex:)) — so automations can set the Lock Screen card's background and foreground. Whentext_coloris omitted the foreground auto-contrasts with the resolved background's luminance, so the black default and any custombackground_colorstay legible. The Dynamic Island background is system-controlled and keeps its white text.Changes:
HALiveActivityAttributes.ContentState: new optionalbackgroundColor(background_color) andtextColor(text_color).HandlerStartOrUpdateLiveActivity: reads both (local push path).HALiveActivityConfiguration/HALockScreenView/HAActivityVisualStyle: resolve the background and foreground (explicittext_color, else luma auto-contrast).Remote (FCM relay) passthrough: home-assistant/mobile-apps-fcm-push#325
Screenshots
Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#
Any other notes
background_colordefaults to#000000;text_coloris optional and overrides the auto-contrast foreground.