From 161074ff75d7760f5d2626c601e4c521a01450e6 Mon Sep 17 00:00:00 2001 From: acclorite Date: Sun, 28 Apr 2024 20:10:20 +0300 Subject: [PATCH] Returned default AnimatedVisibility, before used Custom, which prevented a bug(fixed). (v1.0.1) --- .../components/CustomAnimatedVisibility.kt | 57 +++++++++---------- .../screens/reader/data/ReaderViewModel.kt | 2 +- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/ua/acclorite/book_story/presentation/components/CustomAnimatedVisibility.kt b/app/src/main/java/ua/acclorite/book_story/presentation/components/CustomAnimatedVisibility.kt index 8ef428a6..50d9c201 100644 --- a/app/src/main/java/ua/acclorite/book_story/presentation/components/CustomAnimatedVisibility.kt +++ b/app/src/main/java/ua/acclorite/book_story/presentation/components/CustomAnimatedVisibility.kt @@ -3,16 +3,13 @@ package ua.acclorite.book_story.presentation.components import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.EnterTransition import androidx.compose.animation.ExitTransition -import androidx.compose.animation.core.MutableTransitionState import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.remember -import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Modifier -import kotlinx.coroutines.flow.first /** - * Custom [AnimatedVisibility]. Prevents bug that animation freezes halfway. + * Custom [AnimatedVisibility]. + * Prevents bug that animation freezes halfway. + * FIXED: This bug was fixed. I preserved initial code, if the bug happens again. */ @Composable fun CustomAnimatedVisibility( @@ -22,32 +19,32 @@ fun CustomAnimatedVisibility( exit: ExitTransition, content: @Composable () -> Unit ) { - val visibleState = remember { - MutableTransitionState(visible) - } - - LaunchedEffect(visible) { - if (visible == visibleState.targetState) { - return@LaunchedEffect - } - - if (visibleState.isIdle) { - visibleState.targetState = visible - return@LaunchedEffect - } - - snapshotFlow { - visibleState.isIdle - }.first { - if (it) { - visibleState.targetState = visible - } - it - } - } +// val visibleState = remember { +// MutableTransitionState(visible) +// } +// +// LaunchedEffect(visible) { +// if (visible == visibleState.targetState) { +// return@LaunchedEffect +// } +// +// if (visibleState.isIdle) { +// visibleState.targetState = visible +// return@LaunchedEffect +// } +// +// snapshotFlow { +// visibleState.isIdle +// }.first { +// if (it) { +// visibleState.targetState = visible +// } +// it +// } +// } AnimatedVisibility( - visibleState = visibleState, + visible = visible, modifier = modifier, enter = enter, exit = exit, diff --git a/app/src/main/java/ua/acclorite/book_story/presentation/screens/reader/data/ReaderViewModel.kt b/app/src/main/java/ua/acclorite/book_story/presentation/screens/reader/data/ReaderViewModel.kt index bae67f2a..2ee02f20 100644 --- a/app/src/main/java/ua/acclorite/book_story/presentation/screens/reader/data/ReaderViewModel.kt +++ b/app/src/main/java/ua/acclorite/book_story/presentation/screens/reader/data/ReaderViewModel.kt @@ -310,7 +310,7 @@ class ReaderViewModel @Inject constructor( updateBooks.execute(listOf(_state.value.book)) event.onUpdateCategories( - _state.value.book.copy() + _state.value.book ) event.updatePage( Category.entries.dropLastWhile {