refreshable
Adds an asynchronous handler that can update the data the view displays when a person initiates a request, such as by pulling to refresh.
Declaration
compose().refreshable({
action: () => void,
})nonisolated func refreshable(
action: @escaping @Sendable () async -> Void
) -> some ViewParameters
options.action*() => voidAn asynchronous handler that SwiftUI executes when a person requests a refresh. Use this handler to initiate an update of model data displayed in the modified view. Use
awaitin front of any asynchronous calls inside the handler.
Return value
A view with a new refresh action in its environment.
Discussion
Apply this modifier to a view to set the EnvironmentValues.refresh
value in the view's environment to a RefreshAction instance that
uses the specified action as its handler. Views that detect the
presence of the instance can change their appearance to provide a
way for a person to execute the handler.
For example, when you apply this modifier on iOS and iPadOS to a
List, the list enables a standard pull-to-refresh gesture that
refreshes the list contents. When a person drags the top of the
scrollable area downward, the view reveals a progress indicator
and executes the specified handler. The indicator remains visible
for the duration of the refresh, which runs asynchronously:
List(mailbox.conversations) { conversation in
ConversationCell(conversation)
}
.refreshable {
await mailbox.fetch()
}You can add refresh capability to your own views as well. For
information on how to do that, see RefreshAction.
See also
More in Lists and tables.
- deleteDisabledAdds a condition for whether the view's view hierarchy is deletable.
- listItemTintSets the tint effect for content in a list.
- listRowBackgroundPlaces a custom background view behind a list row item.
- listRowInsetsSets the insets of rows in a list on the specified edges.
- listRowSeparatorSets the display mode for the separator associated with this specific row.
- listRowSeparatorTintSets the tint color associated with a row.
- listRowSpacingSets the vertical spacing between two adjacent rows in a List.
- listSectionIndexVisibilityChanges the visibility of the list section index.
- listSectionMarginsSet the section margins for the specific edges.
- listSectionSeparatorSets whether to hide the separator associated with a list section.
- listSectionSeparatorTintSets the tint color associated with a section.
- listSectionSpacingSets the spacing between adjacent sections in a List to a custom value.