Skip to content

Commit 2050d1f

Browse files
fix(mobile): respect Live Activity presentation colors
1 parent 9bf349c commit 2050d1f

4 files changed

Lines changed: 159 additions & 14 deletions

File tree

‎apps/mobile/src/widgets/AgentActivity.tsx‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,13 @@ export function AgentActivity(
5656
): LiveActivityLayout {
5757
"widget";
5858

59-
// Use SwiftUI's semantic label colors rather than fixed hex keyed off the
60-
// device color scheme. A Live Activity banner always renders over a dark
61-
// system material regardless of the device's light/dark setting, so
62-
// scheme-derived dark text read as unreadable dark-on-dark on the lock
63-
// screen. Semantic colors adapt to whatever material the OS places them on:
64-
// the dark LA banner and the (light or dark) home-screen widget alike.
65-
const primaryForeground = "primary";
66-
const secondaryForeground = "secondary";
59+
// Hierarchical styles inherit the system's foreground treatment, including
60+
// tinted and vibrant presentations, rather than resolving to a label color.
61+
type Foreground = Parameters<typeof foregroundStyle>[0];
62+
const primaryForeground = { type: "hierarchical", style: "primary" } as const;
63+
const secondaryForeground = { type: "hierarchical", style: "secondary" } as const;
64+
const monochrome =
65+
environment.widgetRenderingMode === "accented" || environment.widgetRenderingMode === "vibrant";
6766

6867
// Status tints mirror the web sidebar's pills
6968
// (apps/web/src/components/Sidebar.logic.ts resolveThreadStatusPill): amber
@@ -72,10 +71,13 @@ export function AgentActivity(
7271
// Mac notification center) renders it on a light one — so pick the web
7372
// palette's light (-600) or dark (-300) variant off the color scheme.
7473
const isLightScheme = environment.colorScheme === "light";
75-
const phaseTint = (phase: AgentActivityPhase | undefined): string => {
74+
const phaseTint = (phase: AgentActivityPhase | undefined): Foreground => {
7675
if (environment.isLuminanceReduced) {
7776
return secondaryForeground;
7877
}
78+
if (monochrome) {
79+
return primaryForeground;
80+
}
7981
switch (phase) {
8082
case "waiting_for_approval":
8183
return isLightScheme ? "#d97706" : "#fcd34d"; // amber-600 / amber-300
@@ -179,7 +181,7 @@ export function AgentActivity(
179181

180182
// SF Symbols, like the logo, ignore frame/foregroundStyle applied directly to
181183
// the image; size + tint them through a container the resizable symbol fills.
182-
const renderGlyph = (systemName: SFName, size: number, color: string) => (
184+
const renderGlyph = (systemName: SFName, size: number, color: Foreground) => (
183185
<HStack modifiers={[frame({ width: size, height: size }), foregroundStyle(color)]}>
184186
<Image systemName={systemName} modifiers={[resizable()]} />
185187
</HStack>
@@ -229,7 +231,7 @@ export function AgentActivity(
229231
// frame the resizable image fills and tint it through the container's
230232
// foreground style, which the template image inherits. The 3:2 frame matches
231233
// the glyph's aspect ratio so it never distorts.
232-
const renderLogo = (height: number, color: string) => (
234+
const renderLogo = (height: number, color: Foreground) => (
233235
<HStack modifiers={[frame({ width: height * 1.5, height }), foregroundStyle(color)]}>
234236
<Image assetName="T3Mark" modifiers={[resizable()]} />
235237
</HStack>

‎patches/[email protected]‎

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
diff --git a/build/Widgets.types.d.ts b/build/Widgets.types.d.ts
2+
index 15e026868625ce20a3e359e5cc8e5c7e937c4650..dec7371d74e4f36998a1a170e4fc6557c0962b86 100644
3+
--- a/build/Widgets.types.d.ts
4+
+++ b/build/Widgets.types.d.ts
5+
@@ -90,6 +90,8 @@ export type LiveActivityEnvironment = {
6+
* The color scheme of the activity's environment.
7+
*/
8+
colorScheme: 'light' | 'dark';
9+
+ /** The rendering mode supplied by WidgetKit for this presentation. */
10+
+ widgetRenderingMode?: WidgetRenderingMode;
11+
/**
12+
* Whether the activity is displayed in a context with reduced luminance.
13+
* @platform iOS 16+
14+
diff --git a/ios/Widgets/Utils.swift b/ios/Widgets/Utils.swift
15+
index 2b4c044b597de7e0fab42dbc47af14d8bb521838..8ca92fdf4c15b0d4e217556da7e1aa0345662c79 100644
16+
--- a/ios/Widgets/Utils.swift
17+
+++ b/ios/Widgets/Utils.swift
18+
@@ -91,6 +91,7 @@ func getLiveActivityEnvironment(for environment: EnvironmentValues, in context:
19+
"colorScheme": "\(environment.colorScheme)"
20+
]
21+
22+
+ env["widgetRenderingMode"] = environment.widgetRenderingMode.description
23+
env["isLuminanceReduced"] = environment.isLuminanceReduced
24+
env["isActivityFullscreen"] = environment.isActivityFullscreen
25+
if #available(iOS 16.2, *) {
26+
diff --git a/ios/Widgets/WidgetLiveActivity.swift b/ios/Widgets/WidgetLiveActivity.swift
27+
index 24d4571a52d3ebe9d785b5d049d8e134a149d513..7051c23b17ac91552e5b5c54606c57086c0ebbea 100644
28+
--- a/ios/Widgets/WidgetLiveActivity.swift
29+
+++ b/ios/Widgets/WidgetLiveActivity.swift
30+
@@ -20,53 +20,41 @@ struct LiveActivityAttributes: ActivityAttributes {
31+
32+
@available(iOS 16.1, *)
33+
public struct WidgetLiveActivity: Widget {
34+
- @Environment(\.self) var env
35+
-
36+
let widgetContext: AppContext = AppContext()
37+
38+
public init() {}
39+
40+
public var body: some WidgetConfiguration {
41+
ActivityConfiguration(for: LiveActivityAttributes.self) { context in
42+
- let nodes = getLiveActivityNodes(
43+
- forName: context.state.name,
44+
- props: context.state.props,
45+
- environment: getLiveActivityEnvironment(for: env, in: context)
46+
- )
47+
// Only apply widgetURL when the activity has one: a hierarchy with more than one
48+
// widgetURL modifier is undefined behavior, and layouts can set their own through
49+
// the widgetURL modifier from @expo/ui.
50+
- let banner = LiveActivityBannerView(context: context, nodes: nodes)
51+
+ let banner = LiveActivityBannerView(context: context)
52+
if let url = context.attributes.url.flatMap(URL.init(string:)) {
53+
banner.widgetURL(url)
54+
} else {
55+
banner
56+
}
57+
} dynamicIsland: { context in
58+
- let nodes = getLiveActivityNodes(
59+
- forName: context.state.name,
60+
- props: context.state.props,
61+
- environment: getLiveActivityEnvironment(for: env, in: context)
62+
- )
63+
let island = DynamicIsland {
64+
DynamicIslandExpandedRegion(.center) {
65+
- LiveActivitySectionView(context: context, nodes: nodes, sectionName: "expandedCenter")
66+
+ LiveActivitySectionView(context: context, sectionName: "expandedCenter")
67+
}
68+
DynamicIslandExpandedRegion(.leading) {
69+
- LiveActivitySectionView(context: context, nodes: nodes, sectionName: "expandedLeading")
70+
+ LiveActivitySectionView(context: context, sectionName: "expandedLeading")
71+
}
72+
DynamicIslandExpandedRegion(.trailing) {
73+
- LiveActivitySectionView(context: context, nodes: nodes, sectionName: "expandedTrailing")
74+
+ LiveActivitySectionView(context: context, sectionName: "expandedTrailing")
75+
}
76+
DynamicIslandExpandedRegion(.bottom) {
77+
- LiveActivitySectionView(context: context, nodes: nodes, sectionName: "expandedBottom")
78+
+ LiveActivitySectionView(context: context, sectionName: "expandedBottom")
79+
}
80+
} compactLeading: {
81+
- LiveActivitySectionView(context: context, nodes: nodes, sectionName: "compactLeading")
82+
+ LiveActivitySectionView(context: context, sectionName: "compactLeading")
83+
} compactTrailing: {
84+
- LiveActivitySectionView(context: context, nodes: nodes, sectionName: "compactTrailing")
85+
+ LiveActivitySectionView(context: context, sectionName: "compactTrailing")
86+
} minimal: {
87+
- LiveActivitySectionView(context: context, nodes: nodes, sectionName: "minimal")
88+
+ LiveActivitySectionView(context: context, sectionName: "minimal")
89+
}
90+
if let url = context.attributes.url.flatMap(URL.init(string:)) {
91+
return island.widgetURL(url)
92+
@@ -79,11 +67,16 @@ public struct WidgetLiveActivity: Widget {
93+
94+
@available(iOS 16.1, *)
95+
private struct LiveActivitySectionView: View {
96+
+ @Environment(\.self) var env
97+
let context: ActivityViewContext<LiveActivityAttributes>
98+
- let nodes: [String: Any]
99+
let sectionName: String
100+
101+
var body: some View {
102+
+ let nodes = getLiveActivityNodes(
103+
+ forName: context.state.name,
104+
+ props: context.state.props,
105+
+ environment: getLiveActivityEnvironment(for: env, in: context)
106+
+ )
107+
if let node = nodes[sectionName] as? [String: Any] {
108+
WidgetsDynamicView(name: context.activityID, kind: .liveActivity, node: node)
109+
} else {
110+
@@ -94,10 +87,17 @@ private struct LiveActivitySectionView: View {
111+
112+
@available(iOS 16.1, *)
113+
private struct LiveActivityBannerView: View {
114+
+ // Read inside the rendered view: Widget-level values do not include the
115+
+ // presentation's color scheme, rendering mode, or reduced-luminance state.
116+
+ @Environment(\.self) var env
117+
var context: ActivityViewContext<LiveActivityAttributes>
118+
- let nodes: [String: Any]
119+
120+
var body: some View {
121+
+ let nodes = getLiveActivityNodes(
122+
+ forName: context.state.name,
123+
+ props: context.state.props,
124+
+ environment: getLiveActivityEnvironment(for: env, in: context)
125+
+ )
126+
if #available(iOS 18.0, *) {
127+
LiveActivityBanner(context: context, nodes: nodes)
128+
} else if let node = nodes["banner"] as? [String: Any] {
129+
diff --git a/src/Widgets.types.ts b/src/Widgets.types.ts
130+
index fee5c7475b52218fa0e192a1d347dd32cb0fe1f8..82bf68f631d3a5689064b5acc559d1fc5b4aef85 100644
131+
--- a/src/Widgets.types.ts
132+
+++ b/src/Widgets.types.ts
133+
@@ -104,6 +104,8 @@ export type LiveActivityEnvironment = {
134+
* The color scheme of the activity's environment.
135+
*/
136+
colorScheme: 'light' | 'dark';
137+
+ /** The rendering mode supplied by WidgetKit for this presentation. */
138+
+ widgetRenderingMode?: WidgetRenderingMode;
139+
/**
140+
* Whether the activity is displayed in a context with reduced luminance.
141+
* @platform iOS 16+

‎pnpm-lock.yaml‎

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pnpm-workspace.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ patchedDependencies:
176176
177177
178178
179+
179180
180181
181182

0 commit comments

Comments
 (0)