Widgets

From moasq/nanowave · View interactive version

Widgets is an AI agent skill from the GitHub repository moasq/nanowave. watchOS complications: WidgetKit complication families, accessory sizes, timeline providers for watch face. Use when implementing watchOS-specific patterns related to widgets.

How to use this skill

Skill file

Widgets / Complications (watchOS)

WATCH COMPLICATIONS (WidgetKit):

COMPLICATION FAMILIES:

| Family | Shape | Use Case |

|--------|-------|----------|

| .accessoryCircular | Small circle | Single metric, icon + value |

| .accessoryRectangular | Rectangle | Multi-line text, small chart |

| .accessoryInline | Single line text | Short status text on watch face |

| .accessoryCorner | Corner gauge | Gauge with label |

TIMELINE PROVIDER:

struct ComplicationProvider: TimelineProvider {
    func placeholder(in context: Context) -> ComplicationEntry {
        ComplicationEntry(date: .now, value: 0, label: "—")
    }

    func getSnapshot(in context: Context, completion: @escaping (ComplicationEntry) -> Void) {
        completion(ComplicationEntry(date: .now, value: 42, label: "Steps"))
    }

    func getTimeline(in context: Context, completion: @escaping (Timeline<ComplicationEntry>) -> Void) {
        let entry = ComplicationEntry(date: .now, value: 42, label: "Steps")
        let timeline = Timeline(entries: [entry], policy: .after(.now.addingTimeInterval(900)))
        completion(timeline)
    }
}

struct ComplicationEntry: TimelineEntry {
    let date: Date
    let value: Int
    let label: String
}

COMPLICATION VIEWS:

struct ComplicationView: View {
    var entry: ComplicationProvider.Entry
    @Environment(\.widgetFamily) var family

    var body: some View {
        switch family {
        case .accessoryCircular:
            Gauge(value: Double(entry.value), in: 0...100) {
                Text(entry.label)
            }
            .gaugeStyle(.accessoryCircularCapacity)

        case .accessoryRectangular:
            VStack(alignment: .leading) {
                Text(entry.label)
                    .font(AppTheme.Fonts.headline)
                    .widgetAccentable()
                Text("\(entry.value)")
                    .font(AppTheme.Fonts.title2)
            }

        case .accessoryInline:
            Text("\(entry.label): \(entry.value)")

        case .accessoryCorner:
            Text("\(entry.value)")
                .widgetLabel {
                    Text(entry.label)
                }

        default:
            Text(entry.label)
        }
    }
}

WIDGET DEFINITION:

struct MyComplication: Widget {
    let kind: String = "MyComplication"

    var body: some WidgetConfiguration {
        StaticConfiguration(kind: kind, provider: ComplicationProvider()) { entry in
            ComplicationView(entry: entry)
                .containerBackground(.fill.tertiary, for: .widget)
        }
        .configurationDisplayName("My Complication")
        .description("Shows current status on watch face")
        .supportedFamilies([
            .accessoryCircular,
            .accessoryRectangular,
            .accessoryInline,
            .accessoryCorner
        ])
    }
}

WIDGET BUNDLE:

@main
struct MyWidgetBundle: WidgetBundle {
    var body: some Widget {
        MyComplication()
    }
}

CRITICAL RULES:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.