There is one obvious use-case when we need to return TimelineEntry for widget gallery preview when context.isPreview = true. However, what should be done when context.isPreview = false?
Should I return there the last entry prepared in getTimeline method?
Should I verify if the configuration has changed between calls of getTimeline and getSnapshot?
My widget is using data from API. Should I call it in getSnapshot or only in getTimeline?
If I don't have cached entry, what should I return then? Placeholder entry?
Why they need getSnapshot if they could just take the entry from Timeline?
Currently, I'm returning here either preview entry or the last cached entry during getTimeline also checking if it matches the new configuration. However, I'm not sure if this is the correct approach.
The user chooses to add a widget to their home screen so they press the + button, and they select your app. They haven't yet added the widget, they're just looking at it.
2. The user taps the "Add Widget" button.
Now, the widget is gonna flip around and settle on your home screen. Here, is where the getSnapshot() func comes in - it is shown whenever there's a transition.
In my widget, I check if the context.isPreview, and if so, I display the fake data again. I also check if the configuration.event == nil. If so, at this point the user hasn't chosen an event to display (from the dynamic selection intent) so I'm showing a widget that tells the user to edit the widget and select an event. You could, however, set a default event and have that returned here instead.
Finally, if it's not context.isPreview and configuration.event != nil I then get the actual event the user has chosen so the transition shows that event.
3. The widget is now on-screen. In my case it's telling the user to edit the widget and choose an event. (If you've set a default in the IntentHandler then they wouldn't see this bit asking to edit the widget.) They edit the widget and choose an event.
Now, getSnapshot() is called again to show the transition, but this time it has the actual event (configuration.event != nil) so it displays the actual event in the transition.
getTimeline() is also called so it can provide the timeline of when the widget should refresh.
So, in your case just think about when you want to show actual data. Do you want actual data showing in the placeholder? If so, remember that the placeholder should return quickly, so show *something* then update it with the actual data. If you have that data, you can cache it and use it in getSnapshot() and getTimeline().