Copyright © 2021 Amity Corporation. All rights reserved.
Here’s a quick introduction on WidgeKit, one of the newest iOS14 features presented during the Apple Worldwide Conference 2020.
One of the most interesting topics discussed at WWDC 2020 was about WidgetKit, including the exciting news that this small icon on the home screen of our phone will represent some of the contents within the app itself.
Let’s talk about some key points of WidgetKit itself before we go ahead.
There are 4 key points what makes your WidgetKit great:
Once we make a widget, we can combine those widgets into Smart Stack as well with the relevancy of each Widget. But how does a widget actually work behind the scenes?
WidgetKit works through a Timeline system. WidgetKit extensions are basically background extensions that draw a view hierarchy over time. The data can be either refreshed from the app or through the scheduler within the extension.
To define a widget there are 4 key points :
To create a glanceable experience, your widget needs to avoid stateless UI, no scrolling, no video, or heavy animations as well as providing easy tap interactions with a deep link into your app.
When creating a Widget, there will be 2 concepts :
{% c-block language="swift" %}
public protocol TimelineProvider {
associatedType Entry: TimelineEntry
typealias Context = TimelineProviderContext
func snapshot(with context: Self.Context,
completion: @escaping (Self.Entry) -> ())
func timeline(with context: Self.Context,
completion: @escaping (Timeline<self.entry>) -> ())</self.entry>
}
{% c-block-end %}
Timeline Provider is the datasource that we need to provide to the widget configuration. We can also inject a timeline reload policy to schedule an update. 3 reload policy are :
Some additional information, WidgetKit can use URLSession to kick off a task and use batch requests as well background session, however, be careful with how much network request is needed. Besides that widget relevance is particularly useful when the user has multiple widgets into a smart stack: the stack will be sorted based on each TimelineEntryRelevance, duration, and more.
We’re always seeking ambitious, passionate and community-driven candidates to join us.
View open positions