@devo-bmad-custom/agent-orchestration 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -2
- package/src/.agents/skills/tmux-commands/SKILL.md +1 -1
- package/src/.agents/skills/ui-ux-pro-custom/data/swift-ios-skills/vision-framework/SKILL.md +475 -0
- package/src/.agents/skills/ui-ux-pro-custom/data/swift-ios-skills/vision-framework/references/vision-requests.md +736 -0
- package/src/.agents/skills/ui-ux-pro-custom/data/swift-ios-skills/vision-framework/references/visionkit-scanner.md +738 -0
- package/src/.agents/skills/ui-ux-pro-custom/data/swift-ios-skills/weatherkit/SKILL.md +410 -0
- package/src/.agents/skills/ui-ux-pro-custom/data/swift-ios-skills/weatherkit/references/weatherkit-patterns.md +567 -0
- package/src/.agents/skills/ui-ux-pro-custom/data/swift-ios-skills/widgetkit/SKILL.md +497 -0
- package/src/.agents/skills/ui-ux-pro-custom/data/swift-ios-skills/widgetkit/references/widgetkit-advanced.md +871 -0
- package/src/.agents/skills/ui-ux-pro-custom/data/typography.csv +58 -0
- package/src/.agents/skills/ui-ux-pro-custom/data/ui-reasoning.csv +101 -0
- package/src/.agents/skills/ui-ux-pro-custom/data/ux-guidelines.csv +100 -0
- package/src/.agents/skills/ui-ux-pro-custom/data/web-interface.csv +31 -0
- package/src/.agents/skills/ui-ux-pro-custom/scripts/core.py +253 -0
- package/src/.agents/skills/ui-ux-pro-custom/scripts/design_system.py +1067 -0
- package/src/.agents/skills/ui-ux-pro-custom/scripts/search.py +114 -0
- package/src/.agents/skills/ux-audit/SKILL.md +151 -0
- package/src/.agents/skills/websocket-engineer/SKILL.md +168 -0
- package/src/.agents/skills/websocket-engineer/references/alternatives.md +391 -0
- package/src/.agents/skills/websocket-engineer/references/patterns.md +400 -0
- package/src/.agents/skills/websocket-engineer/references/protocol.md +195 -0
- package/src/.agents/skills/websocket-engineer/references/scaling.md +333 -0
- package/src/.agents/skills/websocket-engineer/references/security.md +474 -0
- package/src/.agents/skills/writing-skills/SKILL.md +655 -0
- package/src/.agents/skills/writing-skills/anthropic-best-practices.md +1150 -0
- package/src/.agents/skills/writing-skills/examples/CLAUDE_MD_TESTING.md +189 -0
- package/src/.agents/skills/writing-skills/graphviz-conventions.dot +172 -0
- package/src/.agents/skills/writing-skills/persuasion-principles.md +187 -0
- package/src/.agents/skills/writing-skills/render-graphs.js +168 -0
- package/src/.agents/skills/writing-skills/testing-skills-with-subagents.md +384 -0
- package/src/.claude/commands/bmad-master.md +15 -0
- package/src/.claude/commands/bmad-review-dry-loop.md +15 -0
- package/src/.claude/commands/bmad-review-dry.md +15 -0
- package/src/.claude/commands/bmad-review-security-loop.md +15 -0
- package/src/.claude/commands/bmad-review-security.md +15 -0
- package/src/.claude/commands/bmad-review-ui-loop.md +15 -0
- package/src/.claude/commands/bmad-review-ui.md +15 -0
- package/src/.claude/commands/bmad-track-compact.md +19 -0
- package/src/.claude/commands/bmad-track-extended.md +19 -0
- package/src/.claude/commands/bmad-track-large.md +19 -0
- package/src/.claude/commands/bmad-track-medium.md +19 -0
- package/src/.claude/commands/bmad-track-nano.md +19 -0
- package/src/.claude/commands/bmad-track-rv.md +18 -0
- package/src/.claude/commands/bmad-track-small.md +19 -0
- package/src/.claude/commands/bmad-triage.md +15 -0
- package/src/.claude/commands/master-orchestrator.md +15 -0
- package/src/_memory/master-orchestrator-sidecar/docs-index.md +3 -0
- package/src/_memory/master-orchestrator-sidecar/instructions.md +2616 -0
- package/src/_memory/master-orchestrator-sidecar/memories.md +8 -0
- package/src/_memory/master-orchestrator-sidecar/session-state.md +15 -0
- package/src/_memory/master-orchestrator-sidecar/triage-history.md +3 -0
- package/src/_memory/master-orchestrator-sidecar/workflows-overview.html +1230 -0
- package/src/core/agents/master-orchestrator.md +54 -0
- package/src/docs/dev/tmux/actions_popup.py +291 -0
- package/src/docs/dev/tmux/actions_popup.sh +110 -0
- package/src/docs/dev/tmux/claude_usage.sh +15 -0
- package/src/docs/dev/tmux/colors.conf +26 -0
- package/src/docs/dev/tmux/cpu_usage.sh +7 -0
- package/src/docs/dev/tmux/dispatch.sh +10 -0
- package/src/docs/dev/tmux/float_init.sh +13 -0
- package/src/docs/dev/tmux/float_term.sh +23 -0
- package/src/docs/dev/tmux/open_clip.sh +14 -0
- package/src/docs/dev/tmux/paste_claude.sh +26 -0
- package/src/docs/dev/tmux/paste_clipboard.sh +13 -0
- package/src/docs/dev/tmux/paste_image_wrapper.sh +98 -0
- package/src/docs/dev/tmux/ram_usage.sh +3 -0
- package/src/docs/dev/tmux/title_sync.sh +54 -0
- package/src/docs/dev/tmux/tmux-setup.md +867 -0
- package/src/docs/dev/tmux/tmux-test.sh +255 -0
- package/src/docs/dev/tmux/tmux.conf +127 -0
- package/src/docs/dev/tmux/xclip +18 -0
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: widgetkit
|
|
3
|
+
description: "Implement, review, or improve widgets, Live Activities, and controls using WidgetKit and ActivityKit. Use when building home screen, Lock Screen, or StandBy widgets with timeline providers; when creating interactive widgets with Button/Toggle and AppIntent actions; when adding Live Activities with Dynamic Island layouts (compact, minimal, expanded); when building Control Center widgets with ControlWidgetButton/ControlWidgetToggle; when configuring widget families, refresh budgets, deep links, push-based reloads, or Liquid Glass rendering; or when setting up widget extensions, App Groups, and entitlements."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# WidgetKit and ActivityKit
|
|
7
|
+
|
|
8
|
+
Build home screen widgets, Lock Screen widgets, Live Activities, Dynamic Island
|
|
9
|
+
presentations, Control Center controls, and StandBy surfaces for iOS 26+.
|
|
10
|
+
|
|
11
|
+
See `references/widgetkit-advanced.md` for timeline strategies, push-based
|
|
12
|
+
updates, Xcode setup, and advanced patterns.
|
|
13
|
+
|
|
14
|
+
## Contents
|
|
15
|
+
|
|
16
|
+
- [Workflow](#workflow)
|
|
17
|
+
- [Widget Protocol and WidgetBundle](#widget-protocol-and-widgetbundle)
|
|
18
|
+
- [Configuration Types](#configuration-types)
|
|
19
|
+
- [TimelineProvider](#timelineprovider)
|
|
20
|
+
- [AppIntentTimelineProvider](#appintenttimelineprovider)
|
|
21
|
+
- [Widget Families](#widget-families)
|
|
22
|
+
- [Interactive Widgets (iOS 17+)](#interactive-widgets-ios-17)
|
|
23
|
+
- [Live Activities and Dynamic Island](#live-activities-and-dynamic-island)
|
|
24
|
+
- [Control Center Widgets (iOS 18+)](#control-center-widgets-ios-18)
|
|
25
|
+
- [Lock Screen Widgets](#lock-screen-widgets)
|
|
26
|
+
- [StandBy Mode](#standby-mode)
|
|
27
|
+
- [iOS 26 Additions](#ios-26-additions)
|
|
28
|
+
- [Common Mistakes](#common-mistakes)
|
|
29
|
+
- [Review Checklist](#review-checklist)
|
|
30
|
+
- [References](#references)
|
|
31
|
+
|
|
32
|
+
## Workflow
|
|
33
|
+
|
|
34
|
+
### 1. Create a new widget
|
|
35
|
+
|
|
36
|
+
1. Add a Widget Extension target in Xcode (File > New > Target > Widget Extension).
|
|
37
|
+
2. Enable App Groups for shared data between the app and widget extension.
|
|
38
|
+
3. Define a `TimelineEntry` struct with a `date` property and display data.
|
|
39
|
+
4. Implement a `TimelineProvider` (static) or `AppIntentTimelineProvider` (configurable).
|
|
40
|
+
5. Build the widget view using SwiftUI, adapting layout per `WidgetFamily`.
|
|
41
|
+
6. Declare the `Widget` conforming struct with a configuration and supported families.
|
|
42
|
+
7. Register all widgets in a `WidgetBundle` annotated with `@main`.
|
|
43
|
+
|
|
44
|
+
### 2. Add a Live Activity
|
|
45
|
+
|
|
46
|
+
1. Define an `ActivityAttributes` struct with a nested `ContentState`.
|
|
47
|
+
2. Add `NSSupportsLiveActivities = YES` to the app's Info.plist.
|
|
48
|
+
3. Create an `ActivityConfiguration` in the widget bundle with Lock Screen content
|
|
49
|
+
and Dynamic Island closures.
|
|
50
|
+
4. Start the activity with `Activity.request(attributes:content:pushType:)`.
|
|
51
|
+
5. Update with `activity.update(_:)` and end with `activity.end(_:dismissalPolicy:)`.
|
|
52
|
+
|
|
53
|
+
### 3. Add a Control Center control
|
|
54
|
+
|
|
55
|
+
1. Define an `AppIntent` for the action.
|
|
56
|
+
2. Create a `ControlWidgetButton` or `ControlWidgetToggle` in the widget bundle.
|
|
57
|
+
3. Use `StaticControlConfiguration` or `AppIntentControlConfiguration`.
|
|
58
|
+
|
|
59
|
+
### 4. Review existing widget code
|
|
60
|
+
|
|
61
|
+
Run through the Review Checklist at the end of this document.
|
|
62
|
+
|
|
63
|
+
## Widget Protocol and WidgetBundle
|
|
64
|
+
|
|
65
|
+
### Widget
|
|
66
|
+
|
|
67
|
+
Every widget conforms to the `Widget` protocol and returns a `WidgetConfiguration`
|
|
68
|
+
from its `body`.
|
|
69
|
+
|
|
70
|
+
```swift
|
|
71
|
+
struct OrderStatusWidget: Widget {
|
|
72
|
+
let kind: String = "OrderStatusWidget"
|
|
73
|
+
|
|
74
|
+
var body: some WidgetConfiguration {
|
|
75
|
+
StaticConfiguration(kind: kind, provider: OrderProvider()) { entry in
|
|
76
|
+
OrderWidgetView(entry: entry)
|
|
77
|
+
}
|
|
78
|
+
.configurationDisplayName("Order Status")
|
|
79
|
+
.description("Track your current order.")
|
|
80
|
+
.supportedFamilies([.systemSmall, .systemMedium])
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### WidgetBundle
|
|
86
|
+
|
|
87
|
+
Use `WidgetBundle` to expose multiple widgets from a single extension.
|
|
88
|
+
|
|
89
|
+
```swift
|
|
90
|
+
@main
|
|
91
|
+
struct MyAppWidgets: WidgetBundle {
|
|
92
|
+
var body: some Widget {
|
|
93
|
+
OrderStatusWidget()
|
|
94
|
+
FavoritesWidget()
|
|
95
|
+
DeliveryActivityWidget() // Live Activity
|
|
96
|
+
QuickActionControl() // Control Center
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Configuration Types
|
|
102
|
+
|
|
103
|
+
Use `StaticConfiguration` for non-configurable widgets. Use `AppIntentConfiguration`
|
|
104
|
+
(recommended) for configurable widgets paired with `AppIntentTimelineProvider`.
|
|
105
|
+
|
|
106
|
+
```swift
|
|
107
|
+
// Static
|
|
108
|
+
StaticConfiguration(kind: "MyWidget", provider: MyProvider()) { entry in
|
|
109
|
+
MyWidgetView(entry: entry)
|
|
110
|
+
}
|
|
111
|
+
// Configurable
|
|
112
|
+
AppIntentConfiguration(kind: "ConfigWidget", intent: SelectCategoryIntent.self,
|
|
113
|
+
provider: CategoryProvider()) { entry in
|
|
114
|
+
CategoryWidgetView(entry: entry)
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Shared Modifiers
|
|
119
|
+
|
|
120
|
+
| Modifier | Purpose |
|
|
121
|
+
|---|---|
|
|
122
|
+
| `.configurationDisplayName(_:)` | Name shown in the widget gallery |
|
|
123
|
+
| `.description(_:)` | Description shown in the widget gallery |
|
|
124
|
+
| `.supportedFamilies(_:)` | Array of `WidgetFamily` values |
|
|
125
|
+
| `.supplementalActivityFamilies(_:)` | Live Activity sizes (`.small`, `.medium`) |
|
|
126
|
+
|
|
127
|
+
## TimelineProvider
|
|
128
|
+
|
|
129
|
+
For static (non-configurable) widgets. Uses completion handlers. Three required methods:
|
|
130
|
+
|
|
131
|
+
```swift
|
|
132
|
+
struct WeatherProvider: TimelineProvider {
|
|
133
|
+
typealias Entry = WeatherEntry
|
|
134
|
+
|
|
135
|
+
func placeholder(in context: Context) -> WeatherEntry {
|
|
136
|
+
WeatherEntry(date: .now, temperature: 72, condition: "Sunny")
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
func getSnapshot(in context: Context, completion: @escaping (WeatherEntry) -> Void) {
|
|
140
|
+
let entry = context.isPreview
|
|
141
|
+
? placeholder(in: context)
|
|
142
|
+
: WeatherEntry(date: .now, temperature: currentTemp, condition: currentCondition)
|
|
143
|
+
completion(entry)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
func getTimeline(in context: Context, completion: @escaping (Timeline<WeatherEntry>) -> Void) {
|
|
147
|
+
Task {
|
|
148
|
+
let weather = await WeatherService.shared.fetch()
|
|
149
|
+
let entry = WeatherEntry(date: .now, temperature: weather.temp, condition: weather.condition)
|
|
150
|
+
let nextUpdate = Calendar.current.date(byAdding: .hour, value: 1, to: .now)!
|
|
151
|
+
completion(Timeline(entries: [entry], policy: .after(nextUpdate)))
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## AppIntentTimelineProvider
|
|
158
|
+
|
|
159
|
+
For configurable widgets. Uses async/await natively. Receives user intent configuration.
|
|
160
|
+
|
|
161
|
+
```swift
|
|
162
|
+
struct CategoryProvider: AppIntentTimelineProvider {
|
|
163
|
+
typealias Entry = CategoryEntry
|
|
164
|
+
typealias Intent = SelectCategoryIntent
|
|
165
|
+
|
|
166
|
+
func placeholder(in context: Context) -> CategoryEntry {
|
|
167
|
+
CategoryEntry(date: .now, categoryName: "Sample", items: [])
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
func snapshot(for config: SelectCategoryIntent, in context: Context) async -> CategoryEntry {
|
|
171
|
+
let items = await DataStore.shared.items(for: config.category)
|
|
172
|
+
return CategoryEntry(date: .now, categoryName: config.category.name, items: items)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
func timeline(for config: SelectCategoryIntent, in context: Context) async -> Timeline<CategoryEntry> {
|
|
176
|
+
let items = await DataStore.shared.items(for: config.category)
|
|
177
|
+
let entry = CategoryEntry(date: .now, categoryName: config.category.name, items: items)
|
|
178
|
+
return Timeline(entries: [entry], policy: .atEnd)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Widget Families
|
|
184
|
+
|
|
185
|
+
### System Families (Home Screen)
|
|
186
|
+
|
|
187
|
+
| Family | Platform |
|
|
188
|
+
|---|---|
|
|
189
|
+
| `.systemSmall` | iOS, iPadOS, macOS, CarPlay (iOS 26+) |
|
|
190
|
+
| `.systemMedium` | iOS, iPadOS, macOS |
|
|
191
|
+
| `.systemLarge` | iOS, iPadOS, macOS |
|
|
192
|
+
| `.systemExtraLarge` | iPadOS only |
|
|
193
|
+
|
|
194
|
+
### Accessory Families (Lock Screen / watchOS)
|
|
195
|
+
|
|
196
|
+
| Family | Platform |
|
|
197
|
+
|---|---|
|
|
198
|
+
| `.accessoryCircular` | iOS, watchOS |
|
|
199
|
+
| `.accessoryRectangular` | iOS, watchOS |
|
|
200
|
+
| `.accessoryInline` | iOS, watchOS |
|
|
201
|
+
| `.accessoryCorner` | watchOS only |
|
|
202
|
+
|
|
203
|
+
Adapt layout per family using `@Environment(\.widgetFamily)`:
|
|
204
|
+
|
|
205
|
+
```swift
|
|
206
|
+
@Environment(\.widgetFamily) var family
|
|
207
|
+
|
|
208
|
+
var body: some View {
|
|
209
|
+
switch family {
|
|
210
|
+
case .systemSmall: CompactView(entry: entry)
|
|
211
|
+
case .systemMedium: DetailedView(entry: entry)
|
|
212
|
+
case .accessoryCircular: CircularView(entry: entry)
|
|
213
|
+
default: FullView(entry: entry)
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Interactive Widgets (iOS 17+)
|
|
219
|
+
|
|
220
|
+
Use `Button` and `Toggle` with `AppIntent` conforming types to perform actions
|
|
221
|
+
directly from a widget without launching the app.
|
|
222
|
+
|
|
223
|
+
```swift
|
|
224
|
+
struct ToggleFavoriteIntent: AppIntent {
|
|
225
|
+
static var title: LocalizedStringResource = "Toggle Favorite"
|
|
226
|
+
@Parameter(title: "Item ID") var itemID: String
|
|
227
|
+
|
|
228
|
+
func perform() async throws -> some IntentResult {
|
|
229
|
+
await DataStore.shared.toggleFavorite(itemID)
|
|
230
|
+
return .result()
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
struct InteractiveWidgetView: View {
|
|
235
|
+
let entry: FavoriteEntry
|
|
236
|
+
var body: some View {
|
|
237
|
+
HStack {
|
|
238
|
+
Text(entry.itemName)
|
|
239
|
+
Spacer()
|
|
240
|
+
Button(intent: ToggleFavoriteIntent(itemID: entry.itemID)) {
|
|
241
|
+
Image(systemName: entry.isFavorite ? "star.fill" : "star")
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
.padding()
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Live Activities and Dynamic Island
|
|
250
|
+
|
|
251
|
+
### ActivityAttributes
|
|
252
|
+
|
|
253
|
+
Define the static and dynamic data model.
|
|
254
|
+
|
|
255
|
+
```swift
|
|
256
|
+
struct DeliveryAttributes: ActivityAttributes {
|
|
257
|
+
struct ContentState: Codable, Hashable {
|
|
258
|
+
var driverName: String
|
|
259
|
+
var estimatedDeliveryTime: ClosedRange<Date>
|
|
260
|
+
var currentStep: DeliveryStep
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
var orderNumber: Int
|
|
264
|
+
var restaurantName: String
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### ActivityConfiguration
|
|
269
|
+
|
|
270
|
+
Provide Lock Screen content and Dynamic Island closures in the widget bundle.
|
|
271
|
+
|
|
272
|
+
```swift
|
|
273
|
+
struct DeliveryActivityWidget: Widget {
|
|
274
|
+
var body: some WidgetConfiguration {
|
|
275
|
+
ActivityConfiguration(for: DeliveryAttributes.self) { context in
|
|
276
|
+
VStack(alignment: .leading) {
|
|
277
|
+
Text(context.attributes.restaurantName).font(.headline)
|
|
278
|
+
HStack {
|
|
279
|
+
Text("Driver: \(context.state.driverName)")
|
|
280
|
+
Spacer()
|
|
281
|
+
Text(timerInterval: context.state.estimatedDeliveryTime, countsDown: true)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
.padding()
|
|
285
|
+
} dynamicIsland: { context in
|
|
286
|
+
DynamicIsland {
|
|
287
|
+
DynamicIslandExpandedRegion(.leading) {
|
|
288
|
+
Image(systemName: "box.truck.fill").font(.title2)
|
|
289
|
+
}
|
|
290
|
+
DynamicIslandExpandedRegion(.trailing) {
|
|
291
|
+
Text(timerInterval: context.state.estimatedDeliveryTime, countsDown: true)
|
|
292
|
+
.font(.caption)
|
|
293
|
+
}
|
|
294
|
+
DynamicIslandExpandedRegion(.center) {
|
|
295
|
+
Text(context.attributes.restaurantName).font(.headline)
|
|
296
|
+
}
|
|
297
|
+
DynamicIslandExpandedRegion(.bottom) {
|
|
298
|
+
HStack {
|
|
299
|
+
ForEach(DeliveryStep.allCases, id: \.self) { step in
|
|
300
|
+
Image(systemName: step.icon)
|
|
301
|
+
.foregroundStyle(step <= context.state.currentStep ? .primary : .tertiary)
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
} compactLeading: {
|
|
306
|
+
Image(systemName: "box.truck.fill")
|
|
307
|
+
} compactTrailing: {
|
|
308
|
+
Text(timerInterval: context.state.estimatedDeliveryTime, countsDown: true)
|
|
309
|
+
.frame(width: 40).monospacedDigit()
|
|
310
|
+
} minimal: {
|
|
311
|
+
Image(systemName: "box.truck.fill")
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### Dynamic Island Regions
|
|
319
|
+
|
|
320
|
+
| Region | Position |
|
|
321
|
+
|---|---|
|
|
322
|
+
| `.leading` | Left of the TrueDepth camera; wraps below |
|
|
323
|
+
| `.trailing` | Right of the TrueDepth camera; wraps below |
|
|
324
|
+
| `.center` | Directly below the camera |
|
|
325
|
+
| `.bottom` | Below all other regions |
|
|
326
|
+
|
|
327
|
+
### Starting, Updating, and Ending
|
|
328
|
+
|
|
329
|
+
```swift
|
|
330
|
+
// Start
|
|
331
|
+
let attributes = DeliveryAttributes(orderNumber: 123, restaurantName: "Pizza Place")
|
|
332
|
+
let state = DeliveryAttributes.ContentState(
|
|
333
|
+
driverName: "Alex",
|
|
334
|
+
estimatedDeliveryTime: Date()...Date().addingTimeInterval(1800),
|
|
335
|
+
currentStep: .preparing
|
|
336
|
+
)
|
|
337
|
+
let content = ActivityContent(state: state, staleDate: nil, relevanceScore: 75)
|
|
338
|
+
let activity = try Activity.request(attributes: attributes, content: content, pushType: .token)
|
|
339
|
+
|
|
340
|
+
// Update (optionally with alert)
|
|
341
|
+
let updated = ActivityContent(state: newState, staleDate: nil, relevanceScore: 90)
|
|
342
|
+
await activity.update(updated)
|
|
343
|
+
await activity.update(updated, alertConfiguration: AlertConfiguration(
|
|
344
|
+
title: "Order Update", body: "Your driver is nearby!", sound: .default
|
|
345
|
+
))
|
|
346
|
+
|
|
347
|
+
// End
|
|
348
|
+
let final = ActivityContent(state: finalState, staleDate: nil, relevanceScore: 0)
|
|
349
|
+
await activity.end(final, dismissalPolicy: .after(.now.addingTimeInterval(3600)))
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
## Control Center Widgets (iOS 18+)
|
|
353
|
+
|
|
354
|
+
```swift
|
|
355
|
+
// Button control
|
|
356
|
+
struct OpenCameraControl: ControlWidget {
|
|
357
|
+
var body: some ControlWidgetConfiguration {
|
|
358
|
+
StaticControlConfiguration(kind: "OpenCamera") {
|
|
359
|
+
ControlWidgetButton(action: OpenCameraIntent()) {
|
|
360
|
+
Label("Camera", systemImage: "camera.fill")
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
.displayName("Open Camera")
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// Toggle control with value provider
|
|
368
|
+
struct FlashlightControl: ControlWidget {
|
|
369
|
+
var body: some ControlWidgetConfiguration {
|
|
370
|
+
StaticControlConfiguration(kind: "Flashlight", provider: FlashlightValueProvider()) { value in
|
|
371
|
+
ControlWidgetToggle(isOn: value, action: ToggleFlashlightIntent()) {
|
|
372
|
+
Label("Flashlight", systemImage: value ? "flashlight.on.fill" : "flashlight.off.fill")
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
.displayName("Flashlight")
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
## Lock Screen Widgets
|
|
381
|
+
|
|
382
|
+
Use accessory families and `AccessoryWidgetBackground`.
|
|
383
|
+
|
|
384
|
+
```swift
|
|
385
|
+
struct StepsWidget: Widget {
|
|
386
|
+
let kind = "StepsWidget"
|
|
387
|
+
var body: some WidgetConfiguration {
|
|
388
|
+
StaticConfiguration(kind: kind, provider: StepsProvider()) { entry in
|
|
389
|
+
ZStack {
|
|
390
|
+
AccessoryWidgetBackground()
|
|
391
|
+
VStack {
|
|
392
|
+
Image(systemName: "figure.walk")
|
|
393
|
+
Text("\(entry.stepCount)").font(.headline)
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
.supportedFamilies([.accessoryCircular, .accessoryRectangular, .accessoryInline])
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
## StandBy Mode
|
|
403
|
+
|
|
404
|
+
`.systemSmall` widgets automatically appear in StandBy (iPhone on charger in
|
|
405
|
+
landscape). Use `@Environment(\.widgetLocation)` for conditional rendering:
|
|
406
|
+
|
|
407
|
+
```swift
|
|
408
|
+
@Environment(\.widgetLocation) var location
|
|
409
|
+
// location == .standBy, .homeScreen, .lockScreen, .carPlay, etc.
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
## iOS 26 Additions
|
|
413
|
+
|
|
414
|
+
### Liquid Glass Support
|
|
415
|
+
|
|
416
|
+
Adapt widgets to the Liquid Glass visual style using `WidgetAccentedRenderingMode`.
|
|
417
|
+
|
|
418
|
+
| Mode | Description |
|
|
419
|
+
|---|---|
|
|
420
|
+
| `.accented` | Accented rendering for Liquid Glass |
|
|
421
|
+
| `.accentedDesaturated` | Accented with desaturation |
|
|
422
|
+
| `.desaturated` | Fully desaturated |
|
|
423
|
+
| `.fullColor` | Full-color rendering |
|
|
424
|
+
|
|
425
|
+
### WidgetPushHandler
|
|
426
|
+
|
|
427
|
+
Enable push-based timeline reloads without scheduled polling.
|
|
428
|
+
|
|
429
|
+
```swift
|
|
430
|
+
struct MyWidgetPushHandler: WidgetPushHandler {
|
|
431
|
+
func pushTokenDidChange(_ pushInfo: WidgetPushInfo, widgets: [WidgetInfo]) {
|
|
432
|
+
let tokenString = pushInfo.token.map { String(format: "%02x", $0) }.joined()
|
|
433
|
+
// Send tokenString to your server
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
### CarPlay Widgets
|
|
439
|
+
|
|
440
|
+
`.systemSmall` widgets render in CarPlay on iOS 26+. Ensure small widget layouts
|
|
441
|
+
are legible at a glance for driver safety.
|
|
442
|
+
|
|
443
|
+
## Common Mistakes
|
|
444
|
+
|
|
445
|
+
1. **Using IntentTimelineProvider instead of AppIntentTimelineProvider.**
|
|
446
|
+
`IntentTimelineProvider` is deprecated. Use `AppIntentTimelineProvider` with
|
|
447
|
+
the App Intents framework.
|
|
448
|
+
|
|
449
|
+
2. **Exceeding the refresh budget.** Widgets have a daily refresh limit. Do not
|
|
450
|
+
call `WidgetCenter.shared.reloadTimelines(ofKind:)` on every minor data change.
|
|
451
|
+
Batch updates and use appropriate `TimelineReloadPolicy` values.
|
|
452
|
+
|
|
453
|
+
3. **Forgetting App Groups for shared data.** The widget extension runs in a
|
|
454
|
+
separate process. Use `UserDefaults(suiteName:)` or a shared App Group
|
|
455
|
+
container for data the widget reads.
|
|
456
|
+
|
|
457
|
+
4. **Performing network calls in placeholder().** `placeholder(in:)` must return
|
|
458
|
+
synchronously with sample data. Use `getTimeline` or `timeline(for:in:)` for
|
|
459
|
+
async work.
|
|
460
|
+
|
|
461
|
+
5. **Missing NSSupportsLiveActivities Info.plist key.** Live Activities will not
|
|
462
|
+
start without `NSSupportsLiveActivities = YES` in the host app's Info.plist.
|
|
463
|
+
|
|
464
|
+
6. **Using the deprecated contentState API.** Use `ActivityContent` for all
|
|
465
|
+
`Activity.request`, `update`, and `end` calls. The `contentState`-based
|
|
466
|
+
methods are deprecated.
|
|
467
|
+
|
|
468
|
+
7. **Not handling the stale state.** Check `context.isStale` in Live Activity
|
|
469
|
+
views and show a fallback (e.g., "Updating...") when content is outdated.
|
|
470
|
+
|
|
471
|
+
8. **Putting heavy logic in the widget view.** Widget views are rendered in a
|
|
472
|
+
size-limited process. Pre-compute data in the timeline provider and pass
|
|
473
|
+
display-ready values through the entry.
|
|
474
|
+
|
|
475
|
+
9. **Ignoring accessory rendering modes.** Lock Screen widgets render in
|
|
476
|
+
`.vibrant` or `.accented` mode, not `.fullColor`. Test with
|
|
477
|
+
`@Environment(\.widgetRenderingMode)` and avoid relying on color alone.
|
|
478
|
+
|
|
479
|
+
10. **Not testing on device.** Dynamic Island and StandBy behavior differ
|
|
480
|
+
significantly from Simulator. Always verify on physical hardware.
|
|
481
|
+
|
|
482
|
+
## Review Checklist
|
|
483
|
+
|
|
484
|
+
- [ ] Widget extension target has App Groups entitlement matching the main app
|
|
485
|
+
- [ ] `@main` is on the `WidgetBundle`, not on individual widgets
|
|
486
|
+
- [ ] `placeholder(in:)` returns synchronously; `getSnapshot`/`snapshot(for:in:)` fast when `isPreview`
|
|
487
|
+
- [ ] Timeline reload policy matches update frequency; `reloadTimelines(ofKind:)` only on data change
|
|
488
|
+
- [ ] Layout adapts per `WidgetFamily`; accessory widgets tested in `.vibrant` mode
|
|
489
|
+
- [ ] Interactive widgets use `AppIntent` with `Button`/`Toggle` only
|
|
490
|
+
- [ ] Live Activity: `NSSupportsLiveActivities = YES`; `ActivityContent` used; Dynamic Island closures implemented
|
|
491
|
+
- [ ] `activity.end(_:dismissalPolicy:)` called; controls use `StaticControlConfiguration`/`AppIntentControlConfiguration`
|
|
492
|
+
- [ ] Timeline entries and Intent types are Sendable; tested on device
|
|
493
|
+
|
|
494
|
+
## References
|
|
495
|
+
|
|
496
|
+
- Advanced guide: `references/widgetkit-advanced.md`
|
|
497
|
+
- Apple docs: [WidgetKit](https://sosumi.ai/documentation/widgetkit) | [ActivityKit](https://sosumi.ai/documentation/activitykit) | [Keeping a widget up to date](https://sosumi.ai/documentation/widgetkit/keeping-a-widget-up-to-date)
|