SwipeRefresh

@Composable()
fun SwipeRefresh(state: SwipeRefreshState, onRefresh: () -> Unit, modifier: Modifier = Modifier, swipeEnabled: Boolean = true, refreshTriggerDistance: Dp = 80.dp, indicatorAlignment: Alignment = Alignment.TopCenter, indicatorPadding: PaddingValues = PaddingValues(0.dp), indicator: @Composable() (state: SwipeRefreshState, refreshTrigger: Dp) -> Unit = { s, trigger -> SwipeRefreshIndicator(s, trigger) }, clipIndicatorToPadding: Boolean = true, content: @Composable() () -> Unit)

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

com.google.accompanist.sample.swiperefresh.SwipeRefreshSample

Parameters

state

the state object to be used to control or observe the SwipeRefresh state.

onRefresh

Lambda which is invoked when a swipe to refresh gesture is completed.

modifier

the modifier to apply to this layout.

swipeEnabled

Whether the the layout should react to swipe gestures or not.

refreshTriggerDistance

The minimum swipe distance which would trigger a refresh.

indicatorAlignment

The alignment of the indicator. Defaults to Alignment.TopCenter.

indicatorPadding

Content padding for the indicator, to inset the indicator in if required.

indicator

the indicator that represents the current state. By default this will use a SwipeRefreshIndicator.

clipIndicatorToPadding

Whether to clip the indicator to indicatorPadding. If false is provided the indicator will be clipped to the content bounds. Defaults to true.

content

The content containing a scroll composable.