mirror of
https://github.com/expo/examples.git
synced 2026-11-13 20:38:07 -10:00
This PR was automatically created by the [upgrade workflow](./.github/workflows/upgrade.yml). > ⚠️ Review the [job logs](https://github.com/expo/examples/actions/runs/28587793003) before merging Co-authored-by: amandeepmittal <[email protected]>
Widgets Example
This example shows how to build an iOS home screen widget and a delivery Live Activity with expo-widgets, and update them from the app.
Launch your own
🚀 How to use
expo-widgetsis not available in the Expo Go app — it requires a development build and iOS 16 or later.
- Install packages with
yarnornpm install. - Run
yarn iosornpm run iosto build and open the app on an iOS simulator or device. - Long-press the home screen, tap the Edit (or +) button, search for the app, and add Counter Widget.
- Tap Increment and update widget in the app and watch the widget update.
- Tap Start delivery Live Activity to kick off a Live Activity that auto-advances Preparing → On the way → Delivered on the Lock Screen and Dynamic Island, with a live ETA countdown and a self-filling progress bar.
📝 Notes
- Learn more about Expo Widgets, including timelines and Live Activities.
- The home screen widget UI in
widgets/CounterWidget.tsxis built with@expo/uiSwiftUI primitives and the'widget'directive, and is registered with theexpo-widgetsconfig plugin inapp.json. - The delivery Live Activity in
widgets/DeliveryActivity.tsxusescreateLiveActivityto render a Lock Screen banner and the Dynamic Island presentations. Its ETA countdown and progress bar update on their own via SwiftUItimerInterval, so the app only pushes a snapshot when the delivery stage changes — seestartDeliveryinApp.tsx. - The background is a
Rectanglefilled with theforegroundStylemodifier'slinearGradientstyle, layered with a grid image in aZStackbehind the content and clipped withclipShape('containerRelativeShape')— see the@expo/uimodifiers for the other gradient types. - Widgets run in a separate process and cannot read the app's asset bundle, so the logo and grid images are copied into
widgetsDirectory(the shared app group container) and referenced by their file URIs — seeensureImageInSharedStorageinApp.tsx.
📁 File Structure
with-widgets
├── App.tsx ➡️ The app screen that updates the widget and runs the Live Activity
├── widgets/CounterWidget.tsx ➡️ The home screen widget UI, written with @expo/ui SwiftUI components
├── widgets/DeliveryActivity.tsx ➡️ The delivery Live Activity UI (Lock Screen + Dynamic Island)
├── assets/images ➡️ Logo and grid images shared with the widget through `widgetsDirectory`
└── app.json ➡️ The `expo-widgets` config plugin configuration