Widgets

From moasq/nanowave · View interactive version

Widgets is an AI agent skill from the GitHub repository moasq/nanowave. WidgetKit: timeline providers, widget families, intent configuration, deep links. Use when implementing app features related to widgets.

How to use this skill

Skill file

Widgets

WIDGETS (WidgetKit):

FRAMEWORK: import WidgetKit

SETUP:

TIMELINE ENTRY (data for a single widget render):

struct MyEntry: TimelineEntry {

let date: Date

let title: String

let value: Double

}

TIMELINE PROVIDER (supplies entries to the system):

struct MyProvider: TimelineProvider {

func placeholder(in context: Context) -> MyEntry {

MyEntry(date: .now, title: "Placeholder", value: 0)

}

func getSnapshot(in context: Context, completion: @escaping (MyEntry) -> Void) {

completion(MyEntry(date: .now, title: "Snapshot", value: 42))

}

func getTimeline(in context: Context, completion: @escaping (Timeline<MyEntry>) -> Void) {

let entry = MyEntry(date: .now, title: "Current", value: 42)

let timeline = Timeline(entries: [entry], policy: .after(.now.addingTimeInterval(3600)))

completion(timeline)

}

}

WIDGET VIEW:

struct MyWidgetView: View {

var entry: MyProvider.Entry

@Environment(\.widgetFamily) var family

var body: some View {

switch family {

case .systemSmall:

VStack { Text(entry.title).font(.headline); Text("\(Int(entry.value))").font(.largeTitle) }

case .systemMedium:

HStack { VStack(alignment: .leading) { Text(entry.title); Text("\(Int(entry.value))").font(.title) }; Spacer() }

default:

Text(entry.title)

}

}

}

WIDGET DEFINITION:

struct MyWidget: Widget {

let kind: String = "MyWidget"

var body: some WidgetConfiguration {

StaticConfiguration(kind: kind, provider: MyProvider()) { entry in

MyWidgetView(entry: entry)

.containerBackground(.fill.tertiary, for: .widget) // REQUIRED iOS 17+

}

.configurationDisplayName("My Widget")

.description("Shows current status")

.supportedFamilies([.systemSmall, .systemMedium])

}

}

WIDGET BUNDLE (when multiple widgets exist):

@main

struct MyWidgetBundle: WidgetBundle {

var body: some Widget {

MyWidget()

AnotherWidget()

}

}

MANDATORY FILES (every widget extension MUST have ALL of these):

  1. {Name}Bundle.swift — @main WidgetBundle entry point. Without this, the extension has no entry point → linker error "undefined symbol: _main" → CodeSign failure.
  2. Provider.swift — TimelineProvider implementation.
  3. WidgetView.swift — The widget's SwiftUI view.
  4. (Optional) Intent.swift — AppIntent for interactive widgets (tap-to-complete, etc.).

CRITICAL RULES:


Extension Configuration

Widgets

WIDGETS (WidgetKit):

FRAMEWORK: import WidgetKit

SETUP:

TIMELINE ENTRY (data for a single widget render):

struct MyEntry: TimelineEntry {

let date: Date

let title: String

let value: Double

}

TIMELINE PROVIDER (supplies entries to the system):

struct MyProvider: TimelineProvider {

func placeholder(in context: Context) -> MyEntry {

MyEntry(date: .now, title: "Placeholder", value: 0)

}

func getSnapshot(in context: Context, completion: @escaping (MyEntry) -> Void) {

completion(MyEntry(date: .now, title: "Snapshot", value: 42))

}

func getTimeline(in context: Context, completion: @escaping (Timeline<MyEntry>) -> Void) {

let entry = MyEntry(date: .now, title: "Current", value: 42)

let timeline = Timeline(entries: [entry], policy: .after(.now.addingTimeInterval(3600)))

completion(timeline)

}

}

WIDGET VIEW:

struct MyWidgetView: View {

var entry: MyProvider.Entry

@Environment(\.widgetFamily) var family

var body: some View {

switch family {

case .systemSmall:

VStack { Text(entry.title).font(AppTheme.Fonts.headline); Text("\(Int(entry.value))").font(AppTheme.Fonts.largeTitle) }

case .systemMedium:

HStack { VStack(alignment: .leading) { Text(entry.title); Text("\(Int(entry.value))").font(AppTheme.Fonts.title) }; Spacer() }

default:

Text(entry.title)

}

}

}

WIDGET DEFINITION:

struct MyWidget: Widget {

let kind: String = "MyWidget"

var body: some WidgetConfiguration {

StaticConfiguration(kind: kind, provider: MyProvider()) { entry in

MyWidgetView(entry: entry)

.containerBackground(.fill.tertiary, for: .widget) // REQUIRED iOS 17+

}

.configurationDisplayName("My Widget")

.description("Shows current status")

.supportedFamilies([.systemSmall, .systemMedium])

}

}

WIDGET BUNDLE (when multiple widgets exist):

@main

struct MyWidgetBundle: WidgetBundle {

var body: some Widget {

MyWidget()

AnotherWidget()

}

}

MANDATORY FILES (every widget extension MUST have ALL of these):

  1. {Name}Bundle.swift — @main WidgetBundle entry point. Without this, the extension has no entry point → linker error "undefined symbol: _main" → CodeSign failure.
  2. Provider.swift — TimelineProvider implementation.
  3. WidgetView.swift — The widget's SwiftUI view.
  4. (Optional) Intent.swift — AppIntent for interactive widgets (tap-to-complete, etc.).

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.