Skip to content

Commit 70e1667

Browse files
authored
Merge pull request #664 from arkivanov/fix-PredictiveBackAnimation
Fixed predictive back animation not working sometimes (regression in 3.0.0-alpha07)
2 parents 5e63d9f + a70f680 commit 70e1667

File tree

1 file changed

+8
-8
lines changed
  • extensions-compose/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/stack/animation/predictiveback

1 file changed

+8
-8
lines changed

extensions-compose/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/stack/animation/predictiveback/PredictiveBackAnimation.kt

+8-8
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private class PredictiveBackAnimation<C : Any, T : Any>(
6969
val activeConfigurations = remember { HashSet<C>() }
7070
val handler = rememberHandler(stack = stack, isGestureEnabled = { activeConfigurations.size == 1 })
7171
val animationProvider = LocalStackAnimationProvider.current
72-
val fallBackAnimation = animation ?: remember(animationProvider, animationProvider::provide) ?: emptyStackAnimation()
72+
val anim = animation ?: remember(animationProvider, animationProvider::provide) ?: emptyStackAnimation()
7373

7474
val childContent =
7575
remember(content) {
@@ -88,9 +88,9 @@ private class PredictiveBackAnimation<C : Any, T : Any>(
8888
Box(modifier = modifier) {
8989
handler.items.forEach { item ->
9090
key(item.key) {
91-
fallBackAnimation(
91+
anim(
9292
stack = item.stack,
93-
modifier = Modifier.fillMaxSize().then(item.modifier),
93+
modifier = Modifier.fillMaxSize().then(item.modifier()),
9494
content = childContent,
9595
)
9696
}
@@ -134,7 +134,7 @@ private class PredictiveBackAnimation<C : Any, T : Any>(
134134
private data class Item<out C : Any, out T : Any>(
135135
val stack: ChildStack<C, T>,
136136
val key: Int,
137-
val modifier: Modifier,
137+
val modifier: () -> Modifier = { Modifier },
138138
)
139139

140140
private class Handler<C : Any, T : Any>(
@@ -145,7 +145,7 @@ private class PredictiveBackAnimation<C : Any, T : Any>(
145145
private val selector: (BackEvent, exitChild: Child.Created<C, T>, enterChild: Child.Created<C, T>) -> PredictiveBackAnimatable,
146146
private val onBack: () -> Unit,
147147
) : BackCallback() {
148-
var items: List<Item<C, T>> by mutableStateOf(listOf(Item(stack = stack, key = key, modifier = Modifier)))
148+
var items: List<Item<C, T>> by mutableStateOf(listOf(Item(stack = stack, key = key)))
149149
private set
150150

151151
private var animatable: PredictiveBackAnimatable? = null
@@ -164,8 +164,8 @@ private class PredictiveBackAnimation<C : Any, T : Any>(
164164

165165
items =
166166
listOf(
167-
Item(stack = stack.dropLast(), key = key + 1, modifier = animatable.enterModifier),
168-
Item(stack = stack, key = key, modifier = animatable.exitModifier),
167+
Item(stack = stack.dropLast(), key = key + 1, modifier = animatable::enterModifier),
168+
Item(stack = stack, key = key, modifier = animatable::exitModifier),
169169
)
170170
}
171171

@@ -191,7 +191,7 @@ private class PredictiveBackAnimation<C : Any, T : Any>(
191191
scope.launch {
192192
animatable?.cancel()
193193
animatable = null
194-
items = listOf(Item(stack = stack, key = key, modifier = Modifier))
194+
items = listOf(Item(stack = stack, key = key))
195195
}
196196
}
197197
}

0 commit comments

Comments
 (0)