Skip to content

Live Activity: black background by default + configurable background_color / text_color#4815

Merged
bgoncal merged 5 commits into
mainfrom
feat/live-activity-background-color
Jun 24, 2026
Merged

Live Activity: black background by default + configurable background_color / text_color#4815
bgoncal merged 5 commits into
mainfrom
feat/live-activity-background-color

Conversation

@bgoncal

@bgoncal bgoncal commented Jun 23, 2026

Copy link
Copy Markdown
Member

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_color and text_color notification fields — parsed with the same rules as notification_icon_color (CSS names / 3-6-8-digit hex via UIColor(hex:)) — so automations can set the Lock Screen card's background and foreground. When text_color is omitted the foreground auto-contrasts with the resolved background's luminance, so the black default and any custom background_color stay legible. The Dynamic Island background is system-controlled and keeps its white text.

Changes:

  • HALiveActivityAttributes.ContentState: new optional backgroundColor (background_color) and textColor (text_color).
  • HandlerStartOrUpdateLiveActivity: reads both (local push path).
  • HALiveActivityConfiguration / HALockScreenView / HAActivityVisualStyle: resolve the background and foreground (explicit text_color, else luma auto-contrast).
  • Tests: contract (wire keys + key set + round-trip) and handler parsing.

Remote (FCM relay) passthrough: home-assistant/mobile-apps-fcm-push#325

Screenshots

Screenshot 2026-06-23 at 20 53 50

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#

Any other notes

  • background_color defaults to #000000; text_color is optional and overrides the auto-contrast foreground.
  • The Dynamic Island background is owned by the system; these fields apply to the Lock Screen presentation.

…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>
@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

⚠️ Unused L10n strings detected

Found 21 unused localization strings in the codebase.

Click to see details
Parsing Strings.swift...
Found 1714 L10n strings

Reading all Swift source code...
Read 5745003 characters of Swift code

Checking for unused strings...
Checked 100/1714 strings...
Checked 200/1714 strings...
Checked 300/1714 strings...
Checked 400/1714 strings...
Checked 500/1714 strings...
Checked 600/1714 strings...
Checked 700/1714 strings...
Checked 800/1714 strings...
Checked 900/1714 strings...
Checked 1000/1714 strings...
Checked 1100/1714 strings...
Checked 1200/1714 strings...
Checked 1300/1714 strings...
Checked 1400/1714 strings...
Checked 1500/1714 strings...
Checked 1600/1714 strings...
Checked 1700/1714 strings...

================================================================================
UNUSED STRINGS REPORT
================================================================================

Found 21 unused strings:


ACTIONSCONFIGURATOR:
  - L10n.ActionsConfigurator.Action.createAutomation
    Key: actions_configurator.action.create_automation
    Line: 132
  - L10n.ActionsConfigurator.VisualSection.sceneDefined
    Key: actions_configurator.visual_section.scene_defined
    Line: 172
  - L10n.ActionsConfigurator.VisualSection.serverDefined
    Key: actions_configurator.visual_section.server_defined
    Line: 178

APPINTENTS:
  - L10n.AppIntents.WidgetAction.actionsParameterConfiguration
    Key: app_intents.widget_action.actions_parameter_configuration
    Line: 612

CAMERA:
  - L10n.Camera.serverNotFound
    Key: camera.server_not_found
    Line: 770
  - L10n.Camera.snapshotFailed
    Key: camera.snapshot_failed
    Line: 772

CAMERALIST:
  - L10n.CameraList.noArea
    Key: camera_list.no_area
    Line: 777
  - L10n.CameraList.searchPlaceholder
    Key: camera_list.search_placeholder
    Line: 779

CAMERAS:
  - L10n.Cameras.dragToReorder
    Key: cameras.drag_to_reorder
    Line: 835

SETTINGSDETAILS:
  - L10n.SettingsDetails.Actions.ActionsSynced.footerNoActions
    Key: settings_details.actions.actions_synced.footer_no_actions
    Line: 3954
  - L10n.SettingsDetails.Actions.Scenes.customizeAction
    Key: settings_details.actions.scenes.customize_action
    Line: 3972

URLHANDLER:
  - L10n.UrlHandler.Error.actionNotFound
    Key: url_handler.error.action_not_found
    Line: 4791

WIDGETS:
  - L10n.Widgets.Controls.Automations.placeholderTitle
    Key: widgets.controls.automations.placeholder_title
    Line: 5843
  - L10n.Widgets.Controls.Button.placeholderTitle
    Key: widgets.controls.button.placeholder_title
    Line: 5851
  - L10n.Widgets.Controls.Cover.placeholderTitle
    Key: widgets.controls.cover.placeholder_title
    Line: 5861
  - L10n.Widgets.Controls.Fan.placeholderTitle
    Key: widgets.controls.fan.placeholder_title
    Line: 5871
  - L10n.Widgets.Controls.Light.placeholderTitle
    Key: widgets.controls.light.placeholder_title
    Line: 5881
  - L10n.Widgets.Controls.Scenes.placeholderTitle
    Key: widgets.controls.scenes.placeholder_title
    Line: 6035
  - L10n.Widgets.Controls.Scripts.placeholderTitle
    Key: widgets.controls.scripts.placeholder_title
    Line: 6047
  - L10n.Widgets.Controls.Switch.placeholderTitle
    Key: widgets.controls.switch.placeholder_title
    Line: 6055

ROOT:
  - L10n.noArea
    Key: no_area
    Line: 36

================================================================================
Total unused: 21
================================================================================

To clean up these strings, manually remove them from the Localizable.strings files
and regenerate Strings.swift using SwiftGen.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_color to HALiveActivityAttributes.ContentState (wire key background_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.

Comment thread Sources/Extensions/Widgets/LiveActivity/HALockScreenView.swift
Comment thread Sources/Shared/LiveActivity/HALiveActivityAttributes.swift Outdated
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>
@bgoncal bgoncal changed the title Live Activity: black background by default + configurable background_color Live Activity: black background by default + configurable background_color / text_color Jun 23, 2026
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 63.63636% with 4 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@c01af4c). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...Shared/LiveActivity/HALiveActivityAttributes.swift 33.33% 4 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

bgoncal and others added 3 commits June 23, 2026 19:33
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>
@bgoncal bgoncal merged commit 325e204 into main Jun 24, 2026
17 checks passed
@bgoncal bgoncal deleted the feat/live-activity-background-color branch June 24, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants