Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't animate the previous child after predictive back gesture finished and stack popped #774

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ internal class DefaultStackAnimation<C : Any, T : Any>(
currentStack = stack

val updateItems =
if (stack.active.key == oldStack.active.key) {
items.keys.singleOrNull() != stack.active.key
} else {
items.keys.toList() != stackKeys
when {
stack.active.key == oldStack.active.key -> items.keys.singleOrNull() != stack.active.key
items.size == 1 -> items.keys.single() != stack.active.key
else -> items.keys.toList() != stackKeys
}

if (updateItems) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.arkivanov.decompose.extensions.compose.experimental.stack.animation

import androidx.compose.animation.EnterExitState
import androidx.compose.animation.core.animateFloat
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -20,6 +22,7 @@ import com.arkivanov.essenty.backhandler.BackEvent
import org.junit.Rule
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse

@Suppress("TestFunctionName")
@OptIn(ExperimentalDecomposeApi::class)
Expand Down Expand Up @@ -282,6 +285,44 @@ class PredictiveBackGestureTest {
composeRule.onNodeWithText("3").assertTestTagToRootDoesNotExist { it.startsWith(TEST_TAG_PREFIX) }
}

@Test
fun GIVEN_three_children_in_stack_WHEN_predictive_back_finished_THEN_previous_child_not_animated_after_pop() {
var stack by mutableStateOf(stack("1", "2", "3"))
val values = ArrayList<Float>()

val animation =
DefaultStackAnimation(
onBack = {
values.clear()
stack = stack.dropLast()
}
)


composeRule.setContent {
animation(stack, Modifier) {
val float by transition.animateFloat { state ->
when (state) {
EnterExitState.PreEnter -> 0F
EnterExitState.Visible -> 1F
EnterExitState.PostExit -> 0F
}
}

if (it.configuration == "2") {
values += float
}
}
}

backDispatcher.startPredictiveBack(BackEvent(progress = 0F))
composeRule.waitForIdle()
backDispatcher.back()
composeRule.waitForIdle()

assertFalse(values.any { it < 1F })
}

private fun DefaultStackAnimation(onBack: () -> Unit): DefaultStackAnimation<String, String> =
DefaultStackAnimation(
disableInputDuringAnimation = false,
Expand Down
Loading