Skip to content

Commit

Permalink
Merge pull request #1
Browse files Browse the repository at this point in the history
Migrate from SwipeRefresh to PullToRefreshBox for better Material 3 integration android#955
  • Loading branch information
shahrukhahmed94 authored Jan 6, 2025
2 parents ff2046b + 12734b1 commit 55558ba
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
Empty file.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ dependencies {
implementation(libs.androidx.lifecycle.runtimeCompose)
implementation(libs.androidx.lifecycle.viewModelCompose)
implementation(libs.accompanist.appcompat.theme)
implementation(libs.accompanist.swiperefresh)

debugImplementation(composeBom)
debugImplementation(libs.androidx.compose.ui.tooling.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

package com.example.android.architecture.blueprints.todoapp.util

import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults.Indicator
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState

val primaryDarkColor: Color = Color(0xFF263238)

Expand All @@ -34,6 +37,7 @@ val primaryDarkColor: Color = Color(0xFF263238)
* @param modifier the modifier to apply to this layout.
* @param content (slot) the main content to show
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LoadingContent(
loading: Boolean,
Expand All @@ -45,12 +49,27 @@ fun LoadingContent(
) {
if (empty) {
emptyContent()
} else {
SwipeRefresh(
state = rememberSwipeRefreshState(loading),
onRefresh = onRefresh,
} else {
// Initialize the PullToRefresh state using remember
val pullToRefreshState = rememberPullToRefreshState()

PullToRefreshBox(
isRefreshing = loading, // use the loading directly for refreshing state
onRefresh = onRefresh, // define the onRefresh event
state = pullToRefreshState, // pass the remembered state
modifier = modifier,
content = content,
)
contentAlignment = Alignment.TopStart,
indicator = {
// Define the indicator for pull-to-refresh
Indicator(
modifier = Modifier.align(Alignment.TopCenter),
isRefreshing = loading,
state = pullToRefreshState
)
}
) {
content() // Main content
}
}

}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ kotlinxSerializationJson = "1.7.3"
ksp = "2.1.0-1.0.29"
lint = "31.7.3"
# @keep
materialZ = "1.8.0-alpha07"
minSdk = "21"
okhttp = "4.10.0"
protobuf = "3.21.12"
Expand All @@ -61,7 +62,6 @@ turbine = "0.12.1"
[libraries]
accompanist-appcompat-theme = { group = "com.google.accompanist", name = "accompanist-appcompat-theme", version.ref = "accompanist" }
accompanist-flowlayout = { group = "com.google.accompanist", name = "accompanist-flowlayout", version.ref = "accompanist" }
accompanist-swiperefresh = { group = "com.google.accompanist", name = "accompanist-swiperefresh", version.ref = "accompanist" }
accompanist-systemuicontroller = { group = "com.google.accompanist", name = "accompanist-systemuicontroller", version.ref = "accompanist" }
accompanist-testharness = { group = "com.google.accompanist", name = "accompanist-testharness", version.ref = "accompanist" }
android-desugarJdkLibs = { group = "com.android.tools", name = "desugar_jdk_libs", version.ref = "androidDesugarJdkLibs" }
Expand Down

0 comments on commit 55558ba

Please sign in to comment.