Skip to content

Commit

Permalink
Merge pull request #774 from arkivanov/fix-prev-child-animating-after…
Browse files Browse the repository at this point in the history
…-predictive-back-pop

Don't animate the previous child after predictive back gesture finished and stack popped
  • Loading branch information
arkivanov authored Sep 7, 2024
2 parents ba105fd + d8f7d2d commit 43ef0e1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
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

0 comments on commit 43ef0e1

Please sign in to comment.