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) }, content: @Composable() () -> Unit)

A layout which implements the swipe-to-refresh pattern.

The layout can be used whenever the user has the ability to refresh content via a vertical swipe gesture.

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 just the progress animation, outside of a swipe refresh, 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.

content

The content containing a scroll composable.