diff --git a/README.md b/README.md index 875e60b..a3e5e03 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,73 @@ # pullrefresh -Standalone pull to refresh library for Jetpack Compose multiplatform. +Standalone pull to refresh library for Jetpack Compose multiplatform without the reliance on Material. + +[![Maven Central](https://img.shields.io/maven-central/v/dev.materii.pullrefresh/pullrefresh?style=for-the-badge&label=Maven%20Central)](https://central.sonatype.com/artifact/dev.materii.pullrefresh/pullrefresh/) +[![Repo stars](https://img.shields.io/github/stars/MateriiApps/pullrefresh?style=for-the-badge&logo=github)](https://github.com/MateriiApps/pullrefresh/stargazers) +![Build status](https://img.shields.io/github/actions/workflow/status/MateriiApps/pullrefresh/build.yml?style=for-the-badge&logo=github) + +## Use + +### Add to project + +Gradle (Kotlin): +```kts +implementation("dev.materii.pullrefresh:pullrefresh:$pullRefreshVersion") +``` + +Gradle (Groovy): +```groovy +implementation 'dev.materii.pullrefresh:pullrefresh:$pullRefreshVersion' +``` + +Gradle (Version Catalog): +```toml +materii-pullrefresh = { group = "dev.materii.pullrefresh", name = "pullrefresh", version.ref = "pullrefresh" } +``` + +### Basic setup +> See the [demo project](https://github.com/MateriiApps/pullrefresh/blob/main/demo/src/main/java/dev/materii/pullrefresh/demo/MainActivity.kt). +```kt +@Composable +fun Test() { + var isRefreshing by remember { + mutableStateOf(false) + } + var pullRefreshState = rememberPullRefreshState(refreshing = isRefreshing, onRefresh = { /* Refresh some data here */ }) + + Scaffold( + modifier = Modifier.pullRefresh(pullRefreshState) + ) { + Box( + contentAlignment = Alignment.Center, + modifier = Modifier + .padding(it) + .fillMaxSize() + .verticalScroll(rememberScrollState()) + ) { + PullRefreshIndicator( + refreshing = isRefreshing, + state = pullRefreshState, + modifier = Modifier.align(Alignment.TopCenter) + ) + } +} +``` + +## Notice +All of the included components come directly from the official Jetpack Compose Material library, with only the bare minimum required. + +``` +Copyright 2022 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +``` diff --git a/build.gradle.kts b/build.gradle.kts index 51245b8..7dcb25a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { allprojects { group = "dev.materii.pullrefresh" - version = "1.0.0" + version = "1.0.1" repositories { repositories { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 76571ca..a2e6284 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] agp = "8.2.0-alpha15" kotlin = "1.8.21" -compose-multiplatform = "1.5.0-beta01" +compose-multiplatform = "1.5.0" compose-compiler = "1.4.7" core-ktx = "1.10.1" @@ -9,7 +9,7 @@ core-ktx = "1.10.1" core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" } lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version = "2.6.1" } activity-compose = { group = "androidx.activity", name = "activity-compose", version = "1.7.2" } -material3 = { group = "androidx.compose.material3", name = "material3", version = "1.1.1" } +material3 = { group = "androidx.compose.material3", name = "material3", version = "1.2.0-alpha04" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" } diff --git a/pullrefresh/src/commonMain/kotlin/dev/materii/pullrefresh/PullRefreshState.kt b/pullrefresh/src/commonMain/kotlin/dev/materii/pullrefresh/PullRefreshState.kt index 68b8740..dfadd31 100644 --- a/pullrefresh/src/commonMain/kotlin/dev/materii/pullrefresh/PullRefreshState.kt +++ b/pullrefresh/src/commonMain/kotlin/dev/materii/pullrefresh/PullRefreshState.kt @@ -107,10 +107,10 @@ class PullRefreshState internal constructor( private val adjustedDistancePulled by derivedStateOf { distancePulled * DragMultiplier } private var _refreshing by mutableStateOf(false) - private var _position by mutableFloatStateOf(0f) - private var distancePulled by mutableFloatStateOf(0f) - private var _threshold by mutableFloatStateOf(threshold) - private var _refreshingOffset by mutableFloatStateOf(refreshingOffset) + private var _position by mutableStateOf(0f) + private var distancePulled by mutableStateOf(0f) + private var _threshold by mutableStateOf(threshold) + private var _refreshingOffset by mutableStateOf(refreshingOffset) internal fun onPull(pullDelta: Float): Float { if (_refreshing) return 0f // Already refreshing, do nothing.