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.AnimatedVisibility
|
||||||
import androidx.compose.animation.EnterTransition
|
import androidx.compose.animation.EnterTransition
|
||||||
import androidx.compose.animation.ExitTransition
|
import androidx.compose.animation.ExitTransition
|
||||||
import androidx.compose.animation.core.MutableTransitionState
|
|
||||||
import androidx.compose.runtime.Composable
|
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 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
|
@Composable
|
||||||
fun CustomAnimatedVisibility(
|
fun CustomAnimatedVisibility(
|
||||||
|
|
@ -22,32 +19,32 @@ fun CustomAnimatedVisibility(
|
||||||
exit: ExitTransition,
|
exit: ExitTransition,
|
||||||
content: @Composable () -> Unit
|
content: @Composable () -> Unit
|
||||||
) {
|
) {
|
||||||
val visibleState = remember {
|
// val visibleState = remember {
|
||||||
MutableTransitionState(visible)
|
// MutableTransitionState(visible)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
LaunchedEffect(visible) {
|
// LaunchedEffect(visible) {
|
||||||
if (visible == visibleState.targetState) {
|
// if (visible == visibleState.targetState) {
|
||||||
return@LaunchedEffect
|
// return@LaunchedEffect
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (visibleState.isIdle) {
|
// if (visibleState.isIdle) {
|
||||||
visibleState.targetState = visible
|
// visibleState.targetState = visible
|
||||||
return@LaunchedEffect
|
// return@LaunchedEffect
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
snapshotFlow {
|
// snapshotFlow {
|
||||||
visibleState.isIdle
|
// visibleState.isIdle
|
||||||
}.first {
|
// }.first {
|
||||||
if (it) {
|
// if (it) {
|
||||||
visibleState.targetState = visible
|
// visibleState.targetState = visible
|
||||||
}
|
// }
|
||||||
it
|
// it
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
AnimatedVisibility(
|
AnimatedVisibility(
|
||||||
visibleState = visibleState,
|
visible = visible,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
enter = enter,
|
enter = enter,
|
||||||
exit = exit,
|
exit = exit,
|
||||||
|
|
|
||||||
|
|
@ -310,7 +310,7 @@ class ReaderViewModel @Inject constructor(
|
||||||
updateBooks.execute(listOf(_state.value.book))
|
updateBooks.execute(listOf(_state.value.book))
|
||||||
|
|
||||||
event.onUpdateCategories(
|
event.onUpdateCategories(
|
||||||
_state.value.book.copy()
|
_state.value.book
|
||||||
)
|
)
|
||||||
event.updatePage(
|
event.updatePage(
|
||||||
Category.entries.dropLastWhile {
|
Category.entries.dropLastWhile {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue