PullToRefresh

fun PullToRefresh(isRefreshing: Boolean, onRefresh: () -> Unit, modifier: Modifier = Modifier, pullToRefreshState: PullToRefreshState = rememberPullToRefreshState(), contentPadding: PaddingValues = PaddingValues(0.dp), topAppBarScrollBehavior: ScrollBehavior? = null, color: Color = PullToRefreshDefaults.color, circleSize: Dp = PullToRefreshDefaults.circleSize, refreshTexts: List<String> = PullToRefreshDefaults.refreshTexts, refreshTextStyle: TextStyle = PullToRefreshDefaults.refreshTextStyle, content: @Composable () -> Unit)

A container that supports the "pull-to-refresh" gesture.

This composable follows a hoisted state pattern, where the logical isRefreshing state is managed by the caller (e.g., a ViewModel). It coordinates nested scrolling to enable a pull-to-refresh action, displays a customizable indicator, and triggers a callback when a refresh is requested.

Parameters

isRefreshing

A boolean state representing whether a refresh is currently in progress. This state should be hoisted and is the source of truth for the refresh operation, in both directions: raising it to true while the indicator is idle shows the indicator programmatically (e.g. refresh-on-entry), and lowering it to false ends the refresh. If it is false when the indicator settles into its refreshing state — because it was never raised, or was raised and lowered again before the next frame — the refresh is treated as already finished and the completion animation runs immediately; a true that arrives later shows the indicator again.

onRefresh

A lambda to be invoked when a refresh is triggered by the user. This lambda should initiate the data loading, set isRefreshing to true, and is responsible for eventually setting it back to false upon completion. It is not invoked when the indicator settles while isRefreshing is already true; the gesture joins the refresh in progress.

modifier

The modifier to be applied to this container.

pullToRefreshState

The state object that manages the UI and animations of the indicator. See rememberPullToRefreshState.

contentPadding

The padding to be applied to the content. The top padding is used to correctly offset the refresh indicator.

topAppBarScrollBehavior

An optional ScrollBehavior for a TopAppBar to coordinate scrolling between the app bar and the pull-to-refresh gesture.

color

The color of the refresh indicator.

circleSize

The size of the refresh indicator's animated circle.

refreshTexts

A list of strings representing the text shown in different states.

refreshTextStyle

The TextStyle for the refresh indicator text.

content

The content to be displayed inside the container.