r/reactnative • u/MajaniPlus • 19d ago
Tutorial Native home-screen widgets in an Expo app: Kotlin RemoteViews + WidgetKit, no JS in the widget
https://simpleprayer.app/blog/expo-home-screen-widgetsI wrote up how we built home-screen widgets for an Expo app without running any JavaScript inside them.
The short version:
- The app works out everything ahead of time in TypeScript and saves a 14-day snapshot. The widgets only pick the right slice for the current time.
- Android: our own Expo module draws the widgets with plain RemoteViews in Kotlin. We dropped react-native-android-widget because a widget tap starts a headless JS runtime, and some phone makers’ Android builds kill that kind of background work.
- iOS: a WidgetKit extension generated with `@bacons/apple-targets`, reading the same snapshot from the App Group.
- The one rule that runs natively is written once as shared test cases, which Jest runs against the TypeScript and the Kotlin and Swift code are checked against.
The code is open source (MIT) if you want to dig in. How have others handled widgets in RN/Expo? I’d like to hear what worked for you.
5
Upvotes
1
u/kokerali 19d ago
Great write-up, especially the contract-driven approach with `overlay-cases.json` and clamping `Date()...end` to `min(Date(), end)...end` so a late WidgetKit render doesn't trap on a backwards `ClosedRange`.
A couple of specific details in `TransitionAlarms.kt` and `PendingOverlay.swift` stood out after reading through the repo:
Also appreciate how `Provider.swift` budgets the calm `H:MM` countdown by capping `maxMinuteEntries = 120` and setting the timeline reload policy to `.after(reloadAt)` at the next prayer boundary (https://developer.apple.com/documentation/widgetkit/keeping-a-widget-up-to-date) alongside Android's non-waking `AlarmManager.RTC` minute tick (https://developer.android.com/develop/ui/views/appwidgets/advanced).
1
u/Eloodye-Ehler 18d ago
curious how you handle dynamic data that changes outside the app, or is your data strictly local and predictable for those 14 days? usually a silent push notification to trigger a background refresh helps keep the shared storage updated without needing the full runtime.