Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Cross-Platform Reference

Perry widgets compile from a single TypeScript source to four platforms. The same Widget({...}) declaration produces native code for each target.

Target Flags

PlatformTarget FlagOutput
iOS--target ios-widgetSwiftUI .swift + Info.plist
iOS Simulator--target ios-widget-simulatorSame, simulator SDK
Android--target android-widgetKotlin/Glance .kt + widget_info XML
watchOS--target watchos-widgetSwiftUI .swift (accessory families)
watchOS Simulator--target watchos-widget-simulatorSame, simulator SDK
Wear OS--target wearos-tileKotlin Tiles .kt + manifest

Feature Matrix

FeatureiOSAndroidwatchOSWear OS
TextYesYesYesYes
VStack/HStack/ZStackYesColumn/Row/BoxYesColumn/Row/Box
Image (SF Symbols)YesR.drawableYesR.drawable
SpacerYesYesYesYes
DividerYesSpacer+bgYesSpacer
ForEachYesforEachYesforEach
LabelYesRow compoundYesText fallback
GaugeN/AText fallbackYesCircularProgressIndicator
ConditionalYesifYesif
FamilySwitchYesLocalSizeYesrequestedSize
Config (AppIntent)YesConfig ActivityYes (10+)SharedPrefs
Native providerYesJNIYesJNI
sharedStorageUserDefaultsSharedPrefsUserDefaultsSharedPrefs
Deep linking (url)widgetURLclickable IntentwidgetURLN/A

Platform-Specific Notes

iOS

  • Minimum deployment: iOS 17.0
  • AppIntentConfiguration requires import AppIntents
  • Widget extension memory limit: ~30MB

Android

  • Requires Glance dependency: androidx.glance:glance-appwidget:1.1.0
  • Widget sizes mapped from iOS families: systemSmall=2x2, systemMedium=4x2, systemLarge=4x4
  • minimumScaleFactor not supported in Glance (skipped with warning)

watchOS

  • Minimum deployment: watchOS 9.0
  • Accessory families only (circular, rectangular, inline)
  • Tighter memory (~15-20MB) and refresh budgets (hourly)
  • AppIntent requires watchOS 10+; older versions get StaticConfiguration

Wear OS

  • Same native compilation as Android phone (Wear OS = Android)
  • Requires Horologist + Tiles Material 3 dependencies
  • Tiles are full-screen cards in the carousel
  • Gauge maps to CircularProgressIndicator

Build Instructions

iOS

perry widget.ts --target ios-widget --app-bundle-id com.example.app -o widget_out
xcrun --sdk iphoneos swiftc -target arm64-apple-ios17.0 \
  widget_out/*.swift -framework WidgetKit -framework SwiftUI \
  -o widget_out/WidgetExtension

Android

perry widget.ts --target android-widget --app-bundle-id com.example.app -o widget_out
# Copy .kt files to app/src/main/java/com/example/app/
# Copy xml/ to app/src/main/res/xml/
# Merge AndroidManifest_snippet.xml into AndroidManifest.xml

watchOS

perry widget.ts --target watchos-widget --app-bundle-id com.example.app -o widget_out
xcrun --sdk watchos swiftc -target arm64-apple-watchos9.0 \
  widget_out/*.swift -framework WidgetKit -framework SwiftUI \
  -o widget_out/WidgetExtension

Wear OS

perry widget.ts --target wearos-tile --app-bundle-id com.example.app -o widget_out
# Copy .kt files to Wear OS module
# Add Horologist + Tiles Material 3 dependencies to build.gradle
# Merge AndroidManifest_snippet.xml