Migrate deprecated progress indicator components

This commit is contained in:
Ivan Iskandar 2023-11-16 15:28:43 +07:00
parent 6eb5a25ea1
commit cede2e72b0
No known key found for this signature in database
GPG key ID: 2C57784F9E46D60D
2 changed files with 14 additions and 10 deletions

View file

@ -39,7 +39,7 @@ class ReaderProgressIndicator @JvmOverloads constructor(
@Composable
override fun Content() {
TachiyomiTheme {
CombinedCircularProgressIndicator(progress = progress)
CombinedCircularProgressIndicator(progress = { progress })
}
}

View file

@ -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 })
}
}
}