19.8 · Timeline fallbacks, testing, bundles and rendering modes
The first widget works in the gallery; the second release has to survive no network, a tinted Home Screen, a Lock Screen and a test suite that cannot create a system context.
Mental model. Treat the provider as a pure function from data to a timeline, and the view as a function of the entry and the rendering mode. Everything else is the system’s decision.
Provider and tests
Failing gracefully and testing without a system context.
- What should a timeline provider return when the fetch fails, and what do the reload policies mean as values?
A provider must always complete, because a widget that never receives a timeline shows stale or placeholder content with no explanation. So build the timeline… - How do you unit test a widget’s timeline logic when the provider’s Context cannot be created in a test?
The provider’s methods receive a TimelineProviderContext (family, preview flag, size), and that type has no public initializer: the check shows the compiler…
Bundles and appearance
Many widgets in one extension, and how the system recolours them.
- How do several widgets live in one extension, and what is a widget’s kind used for?
One widget extension can hold many widgets through a WidgetBundle, and that bundle is the extension’s @main. Each widget has a kind string passed to its… - How do widgets adapt to the tinted Home Screen and the Lock Screen: rendering modes, accented content and container backgrounds?
A widget is not always drawn in full colour. @Environment(\.widgetRenderingMode) has three values (printed by the check): fullColor (normal Home Screen)…
More in Extensions, widgets & intents
- 19.1 · Extension processes, limits, and sharing data with the app
- 19.2 · Notification Service and Notification Content extensions
- 19.3 · Share, Action, keyboards, message filtering, web extensions and network extensions
- 19.4 · WidgetKit timelines, families, refresh budgets, interactivity and controls
- 19.5 · App Intents, Shortcuts, Siri and Spotlight
- 19.6 · The watch app model, Watch Connectivity, and complications
- 19.7 · Top Shelf on tvOS, and treating extensions as a product API
- 19.9 · Dependencies, entities and queries, errors, and build-time metadata
- 19.10 · Info.plist, bundle ids, app group containers and shared payloads