Skip to content

A simple and customizable PulltoRefresh library for Jetpack Compose, supporting custom loading indicators.

License

Notifications You must be signed in to change notification settings

FrankieShao/PullToRefresh-Compose

Repository files navigation

PullToRefresh Library for Jetpack Compose

Maven Central License

A simple and customizable "Pull to Refresh" library for Jetpack Compose, supporting custom loading indicators.

Features

  • Easy to integrate "Pull to Refresh" functionality.
  • Support for custom loading indicators.
  • Lightweight and highly customizable.
  • Compatible with LazyColumn, LazyRow, and other composable lists.

Installation

Add the following dependency to your build.gradle.kts:

dependencies {
    implementation("io.github.frankieshao.refreshlayout:refreshlayout:1.0.0")
}

Usage

Basic Setup

Wrap your content composable (e.g., LazyColumn, LazyRow, etc.) with PullToRefresh in your Composable function:

PullToRefresh(
    isRefreshing = isRefreshing,
    onRefresh = { loadData() }
) {
    LazyColumn {
        items(100) { index ->
            Text("Item #$index")
        }
    }
}

Default Indicator:

Default Indicator

Custom Loading Indicator

To use a custom loading indicator, simply provide a composable function for the indicator parameter:

PullToRefresh(
    isRefreshing = isRefreshing,
    onRefresh = { loadData() },
    loadingIndicator = { CustomLoadingIndicator() }
) {}

@Composable
fun CustomIndicator(
    progress: Float,
    isRefreshing: Boolean,
    modifier: Modifier = Modifier
) {
    val rowHeight = if (isRefreshing) { 60.dp } else { (progress * 60).roundToInt().dp }
    Row(
        verticalAlignment = Alignment.Top,
        horizontalArrangement = Arrangement.Center,
        modifier = modifier
           .fillMaxWidth()
           .height(rowHeight)
           .padding(top = 16.dp)
    ) {
        AnimationLoader(
           modifier = Modifier.height(50.dp).width(50.dp),
           isPlaying = isRefreshing,
           resId = R.raw.lottie_anim
        )
    }
}

Custom Indicator:

Default Indicator

License

This library is licensed under the Apache License 2.0. See the LICENSE file for more details.

For any queries or support, please open an issue on the GitHub repository.

About

A simple and customizable PulltoRefresh library for Jetpack Compose, supporting custom loading indicators.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages