Swipe Refresh
A layout which implements the swipe-to-refresh pattern, allowing the user to refresh content via a vertical swipe gesture.
This layout requires its content to be scrollable so that it receives vertical swipe events. The scrollable content does not need to be a direct descendant though. Layouts such as androidx.compose.foundation.lazy.LazyColumn are automatically scrollable, but others such as androidx.compose.foundation.layout.Column require you to provide the androidx.compose.foundation.verticalScroll modifier to that content.
Apps should provide a onRefresh block to be notified each time a swipe to refresh gesture is completed. That block is responsible for updating the state as appropriately, typically by setting SwipeRefreshState.isRefreshing to true once a 'refresh' has been started. Once a refresh has completed, the app should then set SwipeRefreshState.isRefreshing to false.
If an app wishes to show the progress animation outside of a swipe gesture, it can set SwipeRefreshState.isRefreshing as required.
This layout does not clip any of it's contents, including the indicator. If clipping is required, apps can provide the androidx.compose.ui.draw.clipToBounds modifier.
Samples
Parameters
the state object to be used to control or observe the SwipeRefresh state.
Lambda which is invoked when a swipe to refresh gesture is completed.
the modifier to apply to this layout.
Whether the the layout should react to swipe gestures or not.
The minimum swipe distance which would trigger a refresh.
The alignment of the indicator. Defaults to Alignment.TopCenter.
Content padding for the indicator, to inset the indicator in if required.
the indicator that represents the current state. By default this will use a SwipeRefreshIndicator.
Whether to clip the indicator to indicatorPadding. If false is provided the indicator will be clipped to the content bounds. Defaults to true.
The content containing a scroll composable.