Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't animate the previous child after predictive back gesture finish…
Browse files Browse the repository at this point in the history
…ed and stack popped
arkivanov committed Sep 6, 2024
1 parent 776bca2 commit c7ba62f
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -59,6 +59,8 @@ internal class DefaultStackAnimation<C : Any, T : Any>(
val updateItems =
if (stack.active.key == oldStack.active.key) {
items.keys.singleOrNull() != stack.active.key
} else if (items.size == 1) {
items.keys.single() != stack.active.key
} else {
items.keys.toList() != stackKeys
}
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
@@ -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)
@@ -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,

0 comments on commit c7ba62f

Please sign in to comment.