[ad_1]
My app has a widget that permits for personalisation. When the person chooses to edit the widget, it flips to disclose a customization pane. For instance, to illustrate I’ve a climate widget and the one customization choice is town for which to point out the present climate situation.
When the person faucets the present metropolis to decide on a special one, I have to carry out a community request to fetch the obtainable cities which may take a while beneath troublesome community circumstances. In that state of affairs, my widget configuration pane seems to be damaged as a result of nothing occurs after I faucet on the present metropolis. Solely after a number of seconds (when the information has been fetched), the modal display screen seems with the listing of obtainable cities.
However I wish to give the person some visible suggestions that one thing is occurring whereas the cities are loading. How can I obtain that?
Be aware
I discovered this different query on Stackoverflow with a GIF that reveals a loading spinner (exercise indicator / ProgressView) contained in the widget configuration pane. How do I make this factor seem?
Pattern Implementation
That is my pattern implementation in my IntentHandler to simulate a community request earlier than returning. (Tried the identical factor utilizing a completion handler as an alternative of the async perform.) It does not present a loading spinner.
func provideCategoryOptionsCollection(for intent: CityIntent) async throws -> INObjectCollection<Class> {
// Simulate async community request
attempt await Process.sleep(nanoseconds: UInt64(5 * Double(NSEC_PER_SEC)))
let citiesSection: INObjectSection<Metropolis> = INObjectSection(
title: "Cities",
objects: [.singapore, .sydney, .honolulu]
)
return INObjectCollection(sections: [citiesSection])
}
[ad_2]

