Widget generator

From rshankras/claude-code-apple-skills · View interactive version

Widget generator is an AI agent skill from the GitHub repository rshankras/claude-code-apple-skills. Generate WidgetKit widgets for iOS/macOS home screen and lock screen with timeline providers, interactive elements, and App Intent configuration. Use when adding widgets to an app.

How to use this skill

Skill file

Widget Generator

Generate a complete WidgetKit widget implementation with timeline providers, size-specific views, lock screen accessory widgets, interactive elements (iOS 17+), and App Intent configuration.

When This Skill Activates

Use this skill when the user:

Pre-Generation Checks

1. Project Context Detection

2. Conflict Detection

Search for existing widget code:

Glob: **/*Widget*.swift, **/*TimelineProvider*.swift
Grep: "WidgetKit" or "TimelineProvider" or "WidgetBundle" or "WidgetConfiguration"

If an existing widget extension is found:

If a WidgetBundle already exists:

If widget code with the same name exists:

3. Required Capabilities

Widgets require:

Configuration Questions

Ask user via AskUserQuestion:

  1. What is this widget for? (freeform)
  1. Which widget sizes should be supported?
  1. What type of widget?
  1. What is the data source?
  1. How often should the widget update?

Generation Process

Step 1: Determine File Locations

Check project structure:

For widget extension files:

For shared data models (if using App Groups):

Step 2: Create Core Files

Generate these files based on configuration answers:

  1. {Name}Widget.swift -- Widget definition with configuration
  1. {Name}TimelineProvider.swift -- Timeline logic
  1. {Name}Entry.swift -- Timeline entry model
  1. {Name}WidgetViews.swift -- Size-specific views
  1. {Name}AppIntent.swift (if interactive or configurable)
  1. WidgetBundle update -- Register the new widget

Step 3: Generate Code from Templates

Use the templates in templates.md and customize based on user answers:

Widget Design Rules (WWDC20)

Apply these when generating the size-specific views. A good widget idea is at least one of personal (the user's own data), informational (the most-wanted status at a glance), or contextual (the right thing for this moment). Glanceability is the bar — a widget is read in about a second on the way somewhere else.

| Rule | Specific |

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

| Small widget | Max ~4 pieces of information; exactly one tap target (the whole widget) |

| Medium/Large | Multiple tap targets allowed — cell style for visually contained targets, content style for uncontained lists |

| Margins | 16pt default; 11pt acceptable for tighter graphical shapes (circles, glyphs) |

| Corners | Inner shapes must be concentric with the widget's corner radius |

| Layouts | Design each family separately — never scale the small layout up to medium/large |

| Typography | SF Pro, SF Pro Rounded, or SF Mono; custom fonts only when core to the brand |

| Logo | Only if the app aggregates content from multiple sources — and always top-right |

| Text bans | ❌ Instructional text ("tap to refresh") · ❌ "last updated/checked" language |

| Appearance | Support both light and dark |

| Placeholder | Ship a placeholder state (blocked shapes where content will be) for pre-data loading |

Output Format

After generation, provide:

Files Created

MyAppWidgets/
├── {Name}Widget.swift              # Widget definition + configuration
├── {Name}TimelineProvider.swift     # Timeline provider with placeholder/snapshot/timeline
├── {Name}Entry.swift               # TimelineEntry data model
├── {Name}WidgetViews.swift         # Size-specific views for each family
├── {Name}AppIntent.swift           # (if configurable/interactive) App Intent
└── (update WidgetBundle if needed)

Shared/
└── {Name}DataProvider.swift        # (if App Groups) Shared data access

Integration Steps

1. Add the widget extension target (if not present):

2. Enable App Groups (if sharing data with the main app):

3. Register the widget in the WidgetBundle:

@main
struct MyAppWidgets: WidgetBundle {
    var body: some Widget {
        // Existing widgets...
        {Name}Widget()
    }
}

4. Trigger widget updates from the main app when data changes:

import WidgetKit

// Reload a specific widget
WidgetCenter.shared.reloadTimelines(ofKind: "{Name}Widget")

// Or reload all widgets
WidgetCenter.shared.reloadAllTimelines()

5. For App Group data sharing, write from the main app:

let sharedDefaults = UserDefaults(suiteName: "group.com.yourcompany.yourapp")
sharedDefaults?.set(encodedData, forKey: "widgetData")

// Then trigger reload
WidgetCenter.shared.reloadTimelines(ofKind: "{Name}Widget")

Testing Instructions

  1. Simulator support: Widgets can be previewed in Xcode Canvas and tested in Simulator.
  2. Add to home screen: Long-press the home screen > tap "+" > find your app > select the widget size.
  3. Lock screen widgets: Long-press the lock screen > "Customize" > select the widget area.
  4. Preview in Xcode: Use #Preview with timeline entry data for rapid iteration.
  5. Timeline debugging: Use WidgetCenter.shared.getCurrentConfigurations to verify registered widgets.
  6. Interactive widget testing (iOS 17+): Tap buttons/toggles directly on the widget in Simulator or device.
  7. Memory profiling: Widgets have a 40MB memory limit. Profile in Instruments if loading images or large datasets.

Common Widget Patterns

Weather Widget

Calendar / Events Widget

Fitness / Health Widget

Quick Actions Widget

Countdown Widget

Gotchas and Limits

References

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.