A simple and customizable "Pull to Refresh" library for Jetpack Compose, supporting custom loading indicators.
- Easy to integrate "Pull to Refresh" functionality.
- Support for custom loading indicators.
- Lightweight and highly customizable.
- Compatible with
LazyColumn
,LazyRow
, and other composable lists.
Add the following dependency to your build.gradle.kts
:
dependencies {
implementation("io.github.frankieshao.refreshlayout:refreshlayout:1.0.0")
}
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")
}
}
}
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
)
}
}
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.