<@UHAJKUSTU> Is there an option to reverse an anim...
# decompose
p
@Arkadii Ivanov Is there an option to reverse an animation direction conditionally?
Copy code
slide(
          orientation = when (child.instance) {
            is FlowBaseViewModel.Offer, is FlowBaseViewModel.ProPage -> Orientation.Vertical
            else -> Orientation.Horizontal
          },
        )
On vertical mode I’d like it to go up on enter and down on leaving for the vertical variant
a
I think you would have to write something like this:
Copy code
when (child.instance) {
    is FlowBaseViewModel.Offer, is FlowBaseViewModel.ProPage -> slide(orientation = Orientation.Vertical)
    else -> slide(orientation = Orientation.Horizontal)
}
p
Isn’t that literally the same?
a
Oh right.
Can you post more code? Including Children function.
Oh, I got it. You want to invert the direction in the vertical case. Here you go.
Copy code
fun StackAnimator.invert(): StackAnimator =
    StackAnimator { direction, isInitial, onFinished, content -> 
        this(
            direction = direction.invert(),
            isInitial = isInitial,
            onFinished = onFinished,
            content = content,
        )
    }

private fun Direction.invert(): Direction =
    when (this) {
        Direction.ENTER_FRONT -> Direction.ENTER_BACK
        Direction.EXIT_FRONT -> Direction.EXIT_BACK
        Direction.ENTER_BACK -> Direction.ENTER_FRONT
        Direction.EXIT_BACK -> Direction.EXIT_FRONT
    }
So just
slide(orientation = Orientation.Vertical).invert()
.
p
I think the problem here is that `slide`ignores the direction internally
a
You can try - it should work.
slide
will be receiving different
factor
. See the docs here.