{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

PullToRefreshState

@ExperimentalMaterial3Api
public interface PullToRefreshState


The state that is associated with a PullToRefreshContainer. Each instance of PullToRefreshContainer should have its own PullToRefreshState.

PullToRefreshState can be used with other progress indicators like so:

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.ListItem
import androidx.compose.material3.Text
import androidx.compose.material3.pulltorefresh.PullToRefreshState
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll

var itemCount by remember { mutableStateOf(15) }
val state = rememberPullToRefreshState()
if (state.isRefreshing) {
    LaunchedEffect(true) {
        // fetch something
        delay(1500)
        itemCount += 5
        state.endRefresh()
    }
}
Box(Modifier.nestedScroll(state.nestedScrollConnection)) {
    LazyColumn(Modifier.fillMaxSize()) {
        if (!state.isRefreshing) {
            items(itemCount) {
                ListItem({ Text(text = "Item ${itemCount - it}") })
            }
        }
    }
    if (state.isRefreshing) {
        LinearProgressIndicator()
    } else {
        LinearProgressIndicator(progress = { state.progress })
    }
}

Summary

Public methods

abstract void

Sets isRefreshing to false.

abstract @NonNull NestedScrollConnection

A NestedScrollConnection that should be attached to a Modifier.nestedScroll in order to keep track of the scroll events.

abstract float

The threshold (in pixels), above which if a release occurs, a refresh will be called

abstract float

PullRefresh progress towards positionalThreshold.

abstract float

The vertical offset (in pixels) for the PullToRefreshContainer to consume

abstract boolean

Indicates whether a refresh is occurring.

abstract void
setNestedScrollConnection(
    @NonNull NestedScrollConnection nestedScrollConnection
)

A NestedScrollConnection that should be attached to a Modifier.nestedScroll in order to keep track of the scroll events.

abstract void

Sets isRefreshing to true.

Public methods

endRefresh

abstract void endRefresh()

Sets isRefreshing to false.

getNestedScrollConnection

abstract @NonNull NestedScrollConnection getNestedScrollConnection()

A NestedScrollConnection that should be attached to a Modifier.nestedScroll in order to keep track of the scroll events.

getPositionalThreshold

abstract float getPositionalThreshold()

The threshold (in pixels), above which if a release occurs, a refresh will be called

getProgress

@<Error class: unknown class>
abstract float getProgress()

PullRefresh progress towards positionalThreshold. 0.0 indicates no progress, 1.0 indicates complete progress, 1.0 indicates overshoot beyond the provided threshold

getVerticalOffset

@<Error class: unknown class>
abstract float getVerticalOffset()

The vertical offset (in pixels) for the PullToRefreshContainer to consume

isRefreshing

abstract boolean isRefreshing()

Indicates whether a refresh is occurring.

setNestedScrollConnection

abstract void setNestedScrollConnection(
    @NonNull NestedScrollConnection nestedScrollConnection
)

A NestedScrollConnection that should be attached to a Modifier.nestedScroll in order to keep track of the scroll events.

startRefresh

abstract void startRefresh()

Sets isRefreshing to true.