
Implements Material3-based pull-to-refresh functionality with multiplatform support, offering features like customizable indicators and mouse support for seamless user experience across various devices.
A simple and lightweight Compose Multiplatform library that implements Material3-based pull-to-refresh functionality for JVM, Android, and iOS platforms.
Add the dependency to your build.gradle.kts (or build.gradle for Groovy users):
implementation("io.github.lmbotero:pull-to-refresh:<latest-version>")or using version catalog:
[versions]
pullToRefreshVersion = "<latest-version>"
[libraries]
pullToRefresh = { module = "io.github.lmbotero:pull-to-refresh", version.ref = "pullToRefreshVersion" }Then add the dependency to your build.gradle.kts into the common dependencies block as follows:
commonMain.dependencies {
implementation(libs.pullToRefresh)
}Wrap your composable content inside PullToRefreshLayout:
PullToRefreshLayout(
refreshStateEvent =
RefreshStateEvent(
isRefreshing = isLoading,
onRefresh = { /* Fetch data */ },
),
) {
// Your composable content here
}You can set your own implementation of the loading indicator by passing a custom composable into
indicator parameter.
See https://developer.android.com/reference/kotlin/androidx/compose/material3/pulltorefresh/package-summary.html
to see the official material3 pull-to-refresh reference and documentation.
@Composable
fun PullToRefreshLayout(
refreshStateEvent: RefreshStateEvent,
modifier: Modifier = Modifier,
enabled: Boolean = true,
threshold: Dp = PullToRefreshDefaults.PositionalThreshold,
state: PullToRefreshState = rememberPullToRefreshState(),
indicator: @Composable BoxScope.() -> Unit = {
DefaultIndicator(
state = state,
isRefreshing = refreshStateEvent.isRefreshing,
)
},
content: @Composable BoxScope.() -> Unit,
)| Parameter | Type | Description |
|---|---|---|
refreshStateEvent |
RefreshStateEvent |
Represents the current update state and handles the event when it changes |
modifier |
Modifier |
Modifier for the layout |
enabled |
Boolean |
Whether the pull-to-refresh is enabled or not |
threshold |
Dp |
The distance threshold for triggering the refresh event |
state |
PullToRefreshState |
State for the pull-to-refresh |
indicator |
@Composable BoxScope.() -> Unit |
Composable loading indicator |
content |
@Composable BoxScope.() -> Unit |
Composable content |
data class RefreshStateEvent(
val isRefreshing: Boolean,
val onRefresh: () -> Unit,
)| Parameter | Type | Description |
|---|---|---|
isRefreshing |
Boolean |
Whether the refresh is currently in progress or not |
onRefresh |
() -> Unit |
Function to be executed when the refresh event is triggered |
This project is licensed under the MIT License. See the LICENSE file for details.
This library simplifies pull-to-refresh for Compose Multiplatform, making it easy to use and customize! π
A simple and lightweight Compose Multiplatform library that implements Material3-based pull-to-refresh functionality for JVM, Android, and iOS platforms.
Add the dependency to your build.gradle.kts (or build.gradle for Groovy users):
implementation("io.github.lmbotero:pull-to-refresh:<latest-version>")or using version catalog:
[versions]
pullToRefreshVersion = "<latest-version>"
[libraries]
pullToRefresh = { module = "io.github.lmbotero:pull-to-refresh", version.ref = "pullToRefreshVersion" }Then add the dependency to your build.gradle.kts into the common dependencies block as follows:
commonMain.dependencies {
implementation(libs.pullToRefresh)
}Wrap your composable content inside PullToRefreshLayout:
PullToRefreshLayout(
refreshStateEvent =
RefreshStateEvent(
isRefreshing = isLoading,
onRefresh = { /* Fetch data */ },
),
) {
// Your composable content here
}You can set your own implementation of the loading indicator by passing a custom composable into
indicator parameter.
See https://developer.android.com/reference/kotlin/androidx/compose/material3/pulltorefresh/package-summary.html
to see the official material3 pull-to-refresh reference and documentation.
@Composable
fun PullToRefreshLayout(
refreshStateEvent: RefreshStateEvent,
modifier: Modifier = Modifier,
enabled: Boolean = true,
threshold: Dp = PullToRefreshDefaults.PositionalThreshold,
state: PullToRefreshState = rememberPullToRefreshState(),
indicator: @Composable BoxScope.() -> Unit = {
DefaultIndicator(
state = state,
isRefreshing = refreshStateEvent.isRefreshing,
)
},
content: @Composable BoxScope.() -> Unit,
)| Parameter | Type | Description |
|---|---|---|
refreshStateEvent |
RefreshStateEvent |
Represents the current update state and handles the event when it changes |
modifier |
Modifier |
Modifier for the layout |
enabled |
Boolean |
Whether the pull-to-refresh is enabled or not |
threshold |
Dp |
The distance threshold for triggering the refresh event |
state |
PullToRefreshState |
State for the pull-to-refresh |
indicator |
@Composable BoxScope.() -> Unit |
Composable loading indicator |
content |
@Composable BoxScope.() -> Unit |
Composable content |
data class RefreshStateEvent(
val isRefreshing: Boolean,
val onRefresh: () -> Unit,
)| Parameter | Type | Description |
|---|---|---|
isRefreshing |
Boolean |
Whether the refresh is currently in progress or not |
onRefresh |
() -> Unit |
Function to be executed when the refresh event is triggered |
This project is licensed under the MIT License. See the LICENSE file for details.
This library simplifies pull-to-refresh for Compose Multiplatform, making it easy to use and customize! π