https://kotlinlang.org logo
#decompose
Title
# decompose
p

Paul Woitaschek

11/30/2023, 10:07 AM
@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

Arkadii Ivanov

11/30/2023, 10:30 AM
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

Paul Woitaschek

11/30/2023, 10:31 AM
Isn’t that literally the same?
a

Arkadii Ivanov

11/30/2023, 10:31 AM
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

Paul Woitaschek

11/30/2023, 10:48 AM
I think the problem here is that `slide`ignores the direction internally
a

Arkadii Ivanov

11/30/2023, 11:08 AM
You can try - it should work.
slide
will be receiving different
factor
. See the docs here.
2 Views