Index:
- Content projected should be relevant to user according time of the day
- Try to make sure that the widget supports different sizes and is customizable (can be done using intents)
- Make it simple
- Remember, the widget stays on home screen, the place where user hangs for 5-10 seconds before they hop to some other app!
Important Notes:
- Widgets are meant to project important data from your app.
- Widgets are not mini apps
- Widgets should not include the app name or app icon unless it is aggregator of content from some other source (example: News App) In the case you are using app icons, locate it on top right of your app.
- Widgets should not have scrolling or animations.
Static Configuration is the object which helps you configure the content shown in the widget.
It is used like this:
struct Quote_Widget: Widget {
public var body: some WidgetConfiguration {
IntentConfiguration(kind: "Widget",
intent: ConfigurationIntent.self,
provider: Provider(),
placeholder: PlaceholderView()) { entry in
Quote_WidgetEntryView(entry: entry)
}
.configurationDisplayName("The Name")
.description("....")
}
}
Along with StaticConfiguration, you also need an Entry, Provider and something like a Quote_WidgetDisplayName
to use it.
Consider it is like data structure that you are going to use throughout your app. Your Entry should conform to TimelineEntry
and include other data that you are going to use throughout the widget (like the news headline for news app). Like here, we need an entry like following:
struct SimpleEntry: TimelineEntry {
public let date: Date
public let text: String
public let relevance: TimelineEntryRelevance?
}
Provider is the object which is going to tell the StaticConfiguration to update. Your provider should conform to IntentTimelineProvider
. So, here is where the snapshot and updating the time entries stuff goes.
The placeholder view is a view that displays a generic representation of the widget. WidgetKit shows this view on the lock screen, and before rendering the widget’s content.
Smart Stacks is a new feature on iOS 14 which shows relevant Widget according time and utility. The system can handle and predict how relevant a widget is on a smart smart stack using Timeline Entry Relevance. Quoting from documentation:
The range of the scale
is entirely up to you and could be 1 to 100, 50 to 5000, or any other range of positive numbers that’s meaningful to you. WidgetKit calculates the relative difference of scores between entries, so the absolute values don’t matter.
In the entry you are using, add public let relevance: TimelineEntryRelevance?
(for more, check the project)