From 9ec0f73e8778f18001704a6da3a1ac184027efb9 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Thu, 16 Nov 2023 21:01:45 +0700 Subject: [PATCH] Migrate deprecated progress indicator components (#10142) --- .../reader/viewer/ReaderProgressIndicator.kt | 2 +- .../components/CircularProgressIndicator.kt | 22 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderProgressIndicator.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderProgressIndicator.kt index 2bf9cf95f..e91b375ab 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderProgressIndicator.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderProgressIndicator.kt @@ -39,7 +39,7 @@ class ReaderProgressIndicator @JvmOverloads constructor( @Composable override fun Content() { TachiyomiTheme { - CombinedCircularProgressIndicator(progress = progress) + CombinedCircularProgressIndicator(progress = { progress }) } } diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/CircularProgressIndicator.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/CircularProgressIndicator.kt index bda305890..b123e26e5 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/CircularProgressIndicator.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/CircularProgressIndicator.kt @@ -37,16 +37,15 @@ import androidx.compose.ui.tooling.preview.Preview * By always rotating we give the feedback to the user that the application isn't 'stuck'. */ @Composable -fun CombinedCircularProgressIndicator(progress: Float) { - val animatedProgress by animateFloatAsState( - targetValue = progress, - animationSpec = ProgressIndicatorDefaults.ProgressAnimationSpec, - label = "progress", - ) +fun CombinedCircularProgressIndicator( + progress: () -> Float, + modifier: Modifier = Modifier, +) { AnimatedContent( - targetState = progress == 0f, + targetState = progress() == 0f, transitionSpec = { fadeIn() togetherWith fadeOut() }, label = "progressState", + modifier = modifier, ) { indeterminate -> if (indeterminate) { // Indeterminate @@ -63,8 +62,13 @@ fun CombinedCircularProgressIndicator(progress: Float) { ), label = "rotation", ) + val animatedProgress by animateFloatAsState( + targetValue = progress(), + animationSpec = ProgressIndicatorDefaults.ProgressAnimationSpec, + label = "progress", + ) CircularProgressIndicator( - progress = animatedProgress, + progress = { animatedProgress }, modifier = Modifier.rotate(rotation), ) } @@ -101,7 +105,7 @@ private fun CombinedCircularProgressIndicatorPreview() { .fillMaxSize() .padding(it), ) { - CombinedCircularProgressIndicator(progress = progress) + CombinedCircularProgressIndicator(progress = { progress }) } } }