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.

  1. What should a timeline provider return when the fetch fails, and what do the reload policies mean as values? 19.8.1 · L5
    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…
  2. How do you unit test a widget’s timeline logic when the provider’s Context cannot be created in a test? 19.8.2 · L5
    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.

  1. How do several widgets live in one extension, and what is a widget’s kind used for? 19.8.3 · L3
    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…
  2. How do widgets adapt to the tinted Home Screen and the Lock Screen: rendering modes, accented content and container backgrounds? 19.8.4 · L5
    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