AI Skill Report Card
Building Mobile Widgets
YAML--- name: building-mobile-widgets description: Builds native iOS and Android widgets with proper lifecycle management, data handling, and platform-specific UI patterns. Use when creating home screen widgets, app extensions, or glanceable interfaces. ---
Mobile Widget Builder
Quick Start15 / 15
iOS Widget (Swift/WidgetKit):
SWIFTimport WidgetKit import SwiftUI struct SimpleWidget: Widget { let kind: String = "SimpleWidget" var body: some WidgetConfiguration { StaticConfiguration(kind: kind, provider: Provider()) { entry in SimpleWidgetEntryView(entry: entry) } .configurationDisplayName("My Widget") .description("Shows important data at a glance") .supportedFamilies([.systemSmall, .systemMedium]) } } struct SimpleWidgetEntryView: View { var entry: Provider.Entry var body: some View { VStack { Text(entry.title) .font(.headline) Text(entry.value) .font(.caption) .foregroundColor(.secondary) } .padding() } }
Android Widget (Kotlin):
KOTLINclass SimpleWidgetProvider : AppWidgetProvider() { override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) { for (appWidgetId in appWidgetIds) { updateAppWidget(context, appWidgetManager, appWidgetId) } } } private fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int) { val views = RemoteViews(context.packageName, R.layout.simple_widget) views.setTextViewText(R.id.widget_title, "Widget Title") views.setTextViewText(R.id.widget_value, "Current Value") appWidgetManager.updateAppWidget(appWidgetId, views) }
Recommendation▾
Add specific data provider implementation examples for iOS TimelineProvider to make the Quick Start more complete
Workflow13 / 15
iOS Widget Development
Progress:
- Create widget extension target in Xcode
- Define TimelineProvider for data updates
- Build SwiftUI views for each widget family
- Configure widget sizes and display name
- Test on device and simulator
- Handle background refresh limits
Android Widget Development
Progress:
- Create AppWidgetProvider class
- Define widget metadata in XML
- Create RemoteViews layout
- Handle update intervals and user interactions
- Add widget to manifest
- Test across different Android versions
Cross-Platform Considerations
Progress:
- Design consistent visual language
- Adapt to platform-specific constraints
- Plan data sync strategy
- Test update frequencies
- Optimize for battery usage
Recommendation▾
Include concrete update frequency recommendations with actual numbers (e.g., 'update every 15 minutes for weather data')
Examples18 / 20
Example 1: Weather Widget Input: Display current temperature and conditions Output:
- iOS: Small widget showing "72°F" with weather icon
- Android: 2x1 widget with temperature, condition text, and location
Example 2: Task Counter Input: Show remaining tasks from productivity app Output:
- iOS: Medium widget with task count and progress ring
- Android: 4x1 widget with task list and completion percentages
Example 3: Stock Tracker Input: Display portfolio value and change Output:
- iOS: Large widget with multiple stock prices and charts
- Android: Scrollable widget with stock symbols and price changes
Recommendation▾
Provide template code for handling widget configuration activities and user preferences
Best Practices
iOS Widgets:
- Use Timeline entries efficiently (max 100 per day)
- Design for all supported families simultaneously
- Implement placeholder states for loading
- Use App Intents for iOS 16+ interactivity
- Test with reduced motion and accessibility settings
Android Widgets:
- Minimize RemoteViews complexity for performance
- Use PendingIntents for user interactions
- Handle configuration activities properly
- Support both light and dark themes
- Test across different launcher apps
Universal:
- Keep data fresh but respect battery life
- Design for glanceability (5-second rule)
- Use consistent branding across platforms
- Plan for network failures and offline states
- Optimize images and assets for widget sizes
Common Pitfalls
iOS:
- Don't try to update widgets too frequently (timeline limits)
- Don't use complex animations or video content
- Don't assume widgets are always visible
- Don't ignore memory constraints
Android:
- Don't create overly complex RemoteViews hierarchies
- Don't ignore launcher-specific widget behavior
- Don't assume consistent update intervals
- Don't forget to handle widget removal cleanup
General:
- Don't make widgets too information-dense
- Don't ignore platform UI guidelines
- Don't use widgets for critical user actions
- Don't assume users will configure widgets properly