PullRefreshIndicator

Functions summary

Unit
@Composable
@ExperimentalMaterialApi
PullRefreshIndicator(
    refreshing: Boolean,
    state: PullRefreshState,
    modifier: Modifier,
    backgroundColor: Color,
    contentColor: Color,
    scale: Boolean
)

The default indicator for Compose pull-to-refresh, based on Android's SwipeRefreshLayout.

Cmn

Functions

PullRefreshIndicator

@Composable
@ExperimentalMaterialApi
fun PullRefreshIndicator(
    refreshing: Boolean,
    state: PullRefreshState,
    modifier: Modifier = Modifier,
    backgroundColor: Color = MaterialTheme.colors.surface,
    contentColor: Color = contentColorFor(backgroundColor),
    scale: Boolean = false
): Unit

The default indicator for Compose pull-to-refresh, based on Android's SwipeRefreshLayout.

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.ListItem
import androidx.compose.material.Text
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier

val refreshScope = rememberCoroutineScope()
var refreshing by remember { mutableStateOf(false) }
var itemCount by remember { mutableStateOf(15) }

fun refresh() =
    refreshScope.launch {
        refreshing = true
        delay(1500)
        itemCount += 5
        refreshing = false
    }

val state = rememberPullRefreshState(refreshing, ::refresh)

Box(Modifier.pullRefresh(state)) {
    LazyColumn(Modifier.fillMaxSize()) {
        if (!refreshing) {
            items(itemCount) { ListItem { Text(text = "Item ${itemCount - it}") } }
        }
    }

    PullRefreshIndicator(refreshing, state, Modifier.align(Alignment.TopCenter))
}
Parameters
refreshing: Boolean

A boolean representing whether a refresh is occurring.

state: PullRefreshState

The PullRefreshState which controls where and how the indicator will be drawn.

modifier: Modifier = Modifier

Modifiers for the indicator.

backgroundColor: Color = MaterialTheme.colors.surface

The color of the indicator's background.

contentColor: Color = contentColorFor(backgroundColor)

The color of the indicator's arc and arrow.

scale: Boolean = false

A boolean controlling whether the indicator's size scales with pull progress or not.