The best way to control Claude Code, Codex and more from any computer or phone

main
patch 314 lines 13.4 KB
Raw
1 diff --git a/android/src/main/java/expo/modules/widgets/ExpoWidgetsPeekWidget.kt b/android/src/main/java/expo/modules/widgets/ExpoWidgetsPeekWidget.kt
2 index edabde8f51b3bd9162b634e46f2f09686c3a3b8a..1a17f3b12972bff9849d39dc257cf1b63a80c5a9 100644
3 --- a/android/src/main/java/expo/modules/widgets/ExpoWidgetsPeekWidget.kt
4 +++ b/android/src/main/java/expo/modules/widgets/ExpoWidgetsPeekWidget.kt
5 @@ -25,7 +25,8 @@ internal class ExpoWidgetsPeekWidget(
6 val layout = WidgetsLayoutRegistry.layout(appContext, widgetName)
7 ?: return createErrorRoot("No layout found for $widgetName")
8 val props = WidgetsLayoutRegistry.props(appContext, widgetName)
9 - val environment = getWidgetEnvironment(appContext)
10 + val environment = getWidgetEnvironment(appContext) +
11 + mapOf("width" to size.width.value.toDouble(), "height" to size.height.value.toDouble())
12 val node = evaluateLayout(appContext, layout, props, environment)
13
14 return node.toPeekRoot(appContext, InteractionSource.Widget(widgetName), size)
15 diff --git a/build/ExpoWidgets.js b/build/ExpoWidgets.js
16 index 85f3fbdddade637ed6a96fd0c532a22c675d45c5..05b8dd87f58bfc4acf66652ea04cec777f9be7ca 100644
17 --- a/build/ExpoWidgets.js
18 +++ b/build/ExpoWidgets.js
19 @@ -34,6 +34,7 @@ class LiveActivityFactoryStub {
20 getInstances() {
21 return [];
22 }
23 + dismissEnded() {}
24 }
25 class CustomNotificationStub {
26 getId() {
27 diff --git a/build/Widgets.d.ts b/build/Widgets.d.ts
28 index fb37d5dd61d34768907ac397d4a6ddfce675bccb..47a97af1b8138caa10ca6f67bad6798ef1ea4a72 100644
29 --- a/build/Widgets.d.ts
30 +++ b/build/Widgets.d.ts
31 @@ -100,6 +100,8 @@ export declare class LiveActivityFactory<T extends object = object> {
32 * @platform ios
33 */
34 getInstances(): LiveActivity<T>[];
35 + /** Dismisses ended instances that iOS still shows on the Lock Screen. */
36 + dismissEnded(): void;
37 }
38 /**
39 * Creates a dismissal policy that removes the Live Activity at the specified time within a four-hour window.
40 diff --git a/build/Widgets.js b/build/Widgets.js
41 index cc1efce0ce87337ac55d41a66659048c26698870..3ce8897445a1f4d4be3d4ae69ef6231f1ed604f4 100644
42 --- a/build/Widgets.js
43 +++ b/build/Widgets.js
44 @@ -134,6 +134,9 @@ import ExpoWidgetsModule from './ExpoWidgets';
45 */ getInstances() {
46 return this.nativeLiveActivityFactory.getInstances().map((instance)=>new LiveActivity(instance));
47 }
48 + dismissEnded() {
49 + this.nativeLiveActivityFactory.dismissEnded();
50 + }
51 }
52 /**
53 * Creates a dismissal policy that removes the Live Activity at the specified time within a four-hour window.
54 diff --git a/build/Widgets.types.d.ts b/build/Widgets.types.d.ts
55 index 4c474bb2730376c8e182159c096a6031da4864de..f4e2464de5fe0583cd0e893ee4639648fd779033 100644
56 --- a/build/Widgets.types.d.ts
57 +++ b/build/Widgets.types.d.ts
58 @@ -50,6 +50,12 @@ export type WidgetEnvironment<T extends object | undefined = undefined> = {
59 * The color scheme of the widget's environment.
60 */
61 colorScheme?: 'light' | 'dark';
62 + /**
63 + * The widget's current size in dp.
64 + * @platform android
65 + */
66 + width?: number;
67 + height?: number;
68 /**
69 * A Boolean value that indicates whether the display or environment currently requires reduced luminance.
70 *
71 @@ -98,6 +104,10 @@ export type LiveActivityEnvironment = {
72 * @platform ios
73 */
74 colorScheme: 'light' | 'dark';
75 + /** The rendering mode supplied by WidgetKit for this presentation. */
76 + widgetRenderingMode?: WidgetRenderingMode;
77 + /** Whether the presentation OS supports Liquid Glass. @platform iOS 26+ */
78 + isLiquidGlassAvailable?: boolean;
79 /**
80 * Whether the activity is displayed in a context with reduced luminance.
81 * @platform iOS 16+
82 @@ -307,6 +317,7 @@ export declare class NativeLiveActivityFactory extends SharedObject {
83 constructor(name: string, layout: string);
84 start(props?: string, url?: string, staleDate?: number): NativeLiveActivity;
85 getInstances(): NativeLiveActivity[];
86 + dismissEnded(): void;
87 }
88 export declare class NativeLiveActivity extends SharedObject<LiveActivityEvents> {
89 getId(): string;
90 diff --git a/ios/LiveActivityFactory.swift b/ios/LiveActivityFactory.swift
91 index 29e4f1566d188665e301d32bc1ad85640f83e68c..629e547d8604757e89dd571eab7ad43f7c649cdb 100644
92 --- a/ios/LiveActivityFactory.swift
93 +++ b/ios/LiveActivityFactory.swift
94 @@ -14,11 +14,23 @@ final class LiveActivityFactory: SharedObject {
95 WidgetsStorage.set(layout, forKey: "__expo_widgets_live_activity_\(name)_layout")
96 }
97
98 + // iOS ends an activity after 8 hours but leaves it frozen on the Lock Screen for up to
99 + // 4 more. getInstances() can't see it, so dismiss the ended ones directly.
100 + func dismissEnded() {
101 + for activity in Activity<LiveActivityAttributes>.activities
102 + where activity.content.state.name == name && activity.activityState == .ended {
103 + Task { await activity.end(nil, dismissalPolicy: .immediate) }
104 + }
105 + }
106 +
107 func start(props: String?, url: URL?, staleDate: Date?) throws -> LiveActivity {
108 guard ActivityAuthorizationInfo().areActivitiesEnabled else {
109 throw LiveActivitiesNotSupportedException()
110 }
111
112 + // A replacement started beside an ended card would leave both visible.
113 + dismissEnded()
114 +
115 do {
116 let initialState = LiveActivityAttributes.ContentState(name: name, props: props)
117 let activity = try Activity.request(
118 diff --git a/ios/Widgets/Utils.swift b/ios/Widgets/Utils.swift
119 index 76b2199c2d3f879463fed5d2bd49038b0428a2e7..6cb52c3de4ad9696bc0c51ad62401cce96f405e7 100644
120 --- a/ios/Widgets/Utils.swift
121 +++ b/ios/Widgets/Utils.swift
122 @@ -125,6 +125,10 @@ func getLiveActivityEnvironment(for environment: EnvironmentValues, in context:
123 "isStale": context.isStale
124 ]
125
126 + if #available(iOS 26.0, *) {
127 + env["isLiquidGlassAvailable"] = true
128 + }
129 + env["widgetRenderingMode"] = environment.widgetRenderingMode.description
130 if #available(iOS 18.0, *) {
131 env["isActivityUpdateReduced"] = environment.isActivityUpdateReduced
132 env["activityFamily"] = "\(environment.activityFamily)"
133 diff --git a/ios/Widgets/WidgetLiveActivity.swift b/ios/Widgets/WidgetLiveActivity.swift
134 index 4d135c4e4eb1f846315654ed9d835a935d120d42..dae47445b27516fa2464a25b68bddc8f6dec3e1e 100644
135 --- a/ios/Widgets/WidgetLiveActivity.swift
136 +++ b/ios/Widgets/WidgetLiveActivity.swift
137 @@ -19,53 +19,41 @@ struct LiveActivityAttributes: ActivityAttributes {
138 }
139
140 public struct WidgetLiveActivity: Widget {
141 - @Environment(\.self) var env
142 -
143 let widgetContext: AppContext = AppContext()
144
145 public init() {}
146
147 public var body: some WidgetConfiguration {
148 ActivityConfiguration(for: LiveActivityAttributes.self) { context in
149 - let nodes = getLiveActivityNodes(
150 - forName: context.state.name,
151 - props: context.state.props,
152 - environment: getLiveActivityEnvironment(for: env, in: context)
153 - )
154 // Only apply widgetURL when the activity has one: a hierarchy with more than one
155 // widgetURL modifier is undefined behavior, and layouts can set their own through
156 // the widgetURL modifier from @expo/ui.
157 - let banner = LiveActivityBannerView(context: context, nodes: nodes)
158 + let banner = LiveActivityBannerView(context: context)
159 if let url = context.attributes.url.flatMap(URL.init(string:)) {
160 banner.widgetURL(url)
161 } else {
162 banner
163 }
164 } dynamicIsland: { context in
165 - let nodes = getLiveActivityNodes(
166 - forName: context.state.name,
167 - props: context.state.props,
168 - environment: getLiveActivityEnvironment(for: env, in: context)
169 - )
170 let island = DynamicIsland {
171 DynamicIslandExpandedRegion(.center) {
172 - LiveActivitySectionView(context: context, nodes: nodes, sectionName: "expandedCenter")
173 + LiveActivitySectionView(context: context, sectionName: "expandedCenter")
174 }
175 DynamicIslandExpandedRegion(.leading) {
176 - LiveActivitySectionView(context: context, nodes: nodes, sectionName: "expandedLeading")
177 + LiveActivitySectionView(context: context, sectionName: "expandedLeading")
178 }
179 DynamicIslandExpandedRegion(.trailing) {
180 - LiveActivitySectionView(context: context, nodes: nodes, sectionName: "expandedTrailing")
181 + LiveActivitySectionView(context: context, sectionName: "expandedTrailing")
182 }
183 DynamicIslandExpandedRegion(.bottom) {
184 - LiveActivitySectionView(context: context, nodes: nodes, sectionName: "expandedBottom")
185 + LiveActivitySectionView(context: context, sectionName: "expandedBottom")
186 }
187 } compactLeading: {
188 - LiveActivitySectionView(context: context, nodes: nodes, sectionName: "compactLeading")
189 + LiveActivitySectionView(context: context, sectionName: "compactLeading")
190 } compactTrailing: {
191 - LiveActivitySectionView(context: context, nodes: nodes, sectionName: "compactTrailing")
192 + LiveActivitySectionView(context: context, sectionName: "compactTrailing")
193 } minimal: {
194 - LiveActivitySectionView(context: context, nodes: nodes, sectionName: "minimal")
195 + LiveActivitySectionView(context: context, sectionName: "minimal")
196 }
197 if let url = context.attributes.url.flatMap(URL.init(string:)) {
198 return island.widgetURL(url)
199 @@ -77,11 +65,16 @@ public struct WidgetLiveActivity: Widget {
200 }
201
202 private struct LiveActivitySectionView: View {
203 + @Environment(\.self) var env
204 let context: ActivityViewContext<LiveActivityAttributes>
205 - let nodes: [String: Any]
206 let sectionName: String
207
208 var body: some View {
209 + let nodes = getLiveActivityNodes(
210 + forName: context.state.name,
211 + props: context.state.props,
212 + environment: getLiveActivityEnvironment(for: env, in: context)
213 + )
214 if let node = nodes[sectionName] as? [String: Any] {
215 WidgetsDynamicView(name: context.activityID, kind: .liveActivity, node: node)
216 } else {
217 @@ -91,10 +84,17 @@ private struct LiveActivitySectionView: View {
218 }
219
220 private struct LiveActivityBannerView: View {
221 + // Read inside the rendered view: Widget-level values do not include the
222 + // presentation's color scheme, rendering mode, or reduced-luminance state.
223 + @Environment(\.self) var env
224 var context: ActivityViewContext<LiveActivityAttributes>
225 - let nodes: [String: Any]
226
227 var body: some View {
228 + let nodes = getLiveActivityNodes(
229 + forName: context.state.name,
230 + props: context.state.props,
231 + environment: getLiveActivityEnvironment(for: env, in: context)
232 + )
233 if #available(iOS 18.0, *) {
234 LiveActivityBanner(context: context, nodes: nodes)
235 } else if let node = nodes["banner"] as? [String: Any] {
236 diff --git a/ios/WidgetsModule.swift b/ios/WidgetsModule.swift
237 index 285136b3774e531b35c1a3e832506f93f61654be..d36eac46f435a78afda1724d92d685f3fb19406b 100644
238 --- a/ios/WidgetsModule.swift
239 +++ b/ios/WidgetsModule.swift
240 @@ -97,6 +97,10 @@ public final class WidgetsModule: Module {
241 Function("getInstances") { (liveActivity: LiveActivityFactory) in
242 try liveActivity.getInstances()
243 }
244 +
245 + Function("dismissEnded") { (liveActivity: LiveActivityFactory) in
246 + liveActivity.dismissEnded()
247 + }
248 }
249
250 Class("LiveActivity", LiveActivity.self) {
251 diff --git a/src/ExpoWidgets.ts b/src/ExpoWidgets.ts
252 index db1500090738cca841ded2967078b8c594bac738..6863dc94a3bb61196920489e3f10f21b77c0cce9 100644
253 --- a/src/ExpoWidgets.ts
254 +++ b/src/ExpoWidgets.ts
255 @@ -59,6 +59,7 @@ class LiveActivityFactoryStub {
256 getInstances(): NativeLiveActivity[] {
257 return [];
258 }
259 + dismissEnded(): void {}
260 }
261
262 class CustomNotificationStub {
263 diff --git a/src/Widgets.ts b/src/Widgets.ts
264 index 814b3120b254aaea5ccefab0ab52804ca48ecaf8..98189070a124481a0f366c86116552ca0945fcd7 100644
265 --- a/src/Widgets.ts
266 +++ b/src/Widgets.ts
267 @@ -213,6 +213,11 @@ export class LiveActivityFactory<T extends object = object> {
268 .getInstances()
269 .map((instance) => new LiveActivity<T>(instance));
270 }
271 +
272 + /** Dismisses ended instances that iOS still shows on the Lock Screen. */
273 + dismissEnded(): void {
274 + this.nativeLiveActivityFactory.dismissEnded();
275 + }
276 }
277
278 /**
279 diff --git a/src/Widgets.types.ts b/src/Widgets.types.ts
280 index 690d0695c726dd4f260ba3aeb4edb82b9a72cd39..dc700b6f9320406ae567da5f25f88358a5816a8f 100644
281 --- a/src/Widgets.types.ts
282 +++ b/src/Widgets.types.ts
283 @@ -63,6 +63,12 @@ export type WidgetEnvironment<T extends object | undefined = undefined> = {
284 * The color scheme of the widget's environment.
285 */
286 colorScheme?: 'light' | 'dark';
287 + /**
288 + * The widget's current size in dp.
289 + * @platform android
290 + */
291 + width?: number;
292 + height?: number;
293 /**
294 * A Boolean value that indicates whether the display or environment currently requires reduced luminance.
295 *
296 @@ -112,6 +118,10 @@ export type LiveActivityEnvironment = {
297 * @platform ios
298 */
299 colorScheme: 'light' | 'dark';
300 + /** The rendering mode supplied by WidgetKit for this presentation. */
301 + widgetRenderingMode?: WidgetRenderingMode;
302 + /** Whether the presentation OS supports Liquid Glass. @platform iOS 26+ */
303 + isLiquidGlassAvailable?: boolean;
304 /**
305 * Whether the activity is displayed in a context with reduced luminance.
306 * @platform iOS 16+
307 @@ -337,6 +347,7 @@ export declare class NativeLiveActivityFactory extends SharedObject {
308 constructor(name: string, layout: string);
309 start(props?: string, url?: string, staleDate?: number): NativeLiveActivity;
310 getInstances(): NativeLiveActivity[];
311 + dismissEnded(): void;
312 }
313
314 export declare class NativeLiveActivity extends SharedObject<LiveActivityEvents> {