Returned default AnimatedVisibility, before used Custom, which prevented a bug(fixed). (v1.0.1)
This commit is contained in:
parent
456d9fc3c9
commit
161074ff75
2 changed files with 28 additions and 31 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue