PullToRefreshBox
Requires
@OptIn(ExperimentalMaterial3Api::class)
Dependencies
Section titled “Dependencies”implementation("androidx.compose.material3:material3:1.3.0")Basic Usage
Section titled “Basic Usage”@OptIn(ExperimentalMaterial3Api::class)@Composablefun PullToRefreshExample() { var isRefreshing by remember { mutableStateOf(false) } val scope = rememberCoroutineScope()
PullToRefreshBox( isRefreshing = isRefreshing, onRefresh = { scope.launch { isRefreshing = true // Simulate loading delay(2000) isRefreshing = false } } ) { LazyColumn(Modifier.fillMaxSize()) { items(100) { Text("Item $it", modifier = Modifier.padding(16.dp)) } } }}With Custom Indicator
Section titled “With Custom Indicator”@OptIn(ExperimentalMaterial3Api::class)@Composablefun CustomPullToRefresh() { var isRefreshing by remember { mutableStateOf(false) } val state = rememberPullToRefreshState() val scope = rememberCoroutineScope()
PullToRefreshBox( isRefreshing = isRefreshing, onRefresh = { scope.launch { isRefreshing = true delay(2000) isRefreshing = false } }, state = state, indicator = { PullToRefreshDefaults.Indicator( state = state, isRefreshing = isRefreshing, modifier = Modifier.align(Alignment.TopCenter), color = MaterialTheme.colorScheme.primary ) } ) { // Content here }}Key Properties
Section titled “Key Properties”isRefreshing: Boolean- Whether the refresh indicator should be shownonRefresh: () -> Unit- Callback when user triggers refreshstate: PullToRefreshState- State object to control the pull gestureindicator: @Composable- Custom indicator composable