Reputation: 203
Morning, everyone,
I'm developing a widget using an API that sends an array of different sizes depending on the size of the widget (small : 3 news, medium: 6 news, large: 9 news).
I have the impression that there is a problem between the @Environment(\.widgetFamily) var family
and the timeline function (where I call the API) of TimelineProvider.
Indeed in this function the environment variable is always equal to the systemMedium size despite the "real" size of the widget.
Do you also have the same problem on your side ? Is it a known bug from Apple ? How can I solve this bug ?
Thanks for your help :]
Upvotes: 2
Views: 845
Reputation: 3434
Without seeing your code, my best guess is that you're not accessing the family
property of the TimelineProviderContext
passed into the TimelineProvider
.
Your TimelineProvider
should look something like:
struct MyProvider: TimelineProvider {
func snapshot(with context: Context, completion: @escaping (Entry) -> ()) {
fetchNewsArticles(for: context.family) { articles in
// ...
completion(...)
}
}
}
func fetchNewsArticles(for widgetFamily: WidgetFamily, completion: @escaping ... )
{
switch family {
case .systemSmall:
// ...
}
Apple Docs - TimelineProviderContext
Upvotes: 2