Refreshable task with follow-up work after refresh is done #1345
-
I'm wondering how one should do to use the So, for example, let's say I want to do two things as a result of pulling to refresh on the list:
and I want the spinning to stop after task 1 is finished, and then let the images continue to load in the background. To work with the refreshable API, I'm doing this in the view: List(viewStore.rows) { row in
...
}
.refreshable { await viewStore.send(.pulledToRefresh).finish() } where the reducer has something like these lines in it: switch action {
...
case .pulledToRefresh:
return .task { .rowsReloaded(await refreshClient.refreshRows()) }
case .rowsReloaded(let rows):
state.rows = rows
return .run { send in
// fetch the images for the rows
}
...
} This way, the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
@oskarek While it's possible to do a little coordination with your store to make it so refreshable effects are only tied to the first stage, the main thing that stands out to me here is that you're doing image loading in a reducer. Is your reducer doing any significant logic with the images it is loading, and are you testing this logic? We generally do not recommend loading or storing images in your app's domain if it's for display purposes. Instead we recommend using For the more general case, though, you would sequence actions into the store in the .refreshable {
await viewStore.send(.actionThatSuspendsForRefreshing).finish()
viewStore.send(.actionToKickOffWhenRefreshingIsComplete)
} Edit: @mbrandonw reminded me that we also have .refreshable {
await viewStore.send(.action, while: \.isRefreshing)
} |
Beta Was this translation helpful? Give feedback.
@oskarek While it's possible to do a little coordination with your store to make it so refreshable effects are only tied to the first stage, the main thing that stands out to me here is that you're doing image loading in a reducer. Is your reducer doing any significant logic with the images it is loading, and are you testing this logic?
We generally do not recommend loading or storing images in your app's domain if it's for display purposes. Instead we recommend using
AsyncImage
or one of the many open source image loading libraries out there.For the more general case, though, you would sequence actions into the store in the
refreshable
modifier: