voyager icon indicating copy to clipboard operation
voyager copied to clipboard

What is the proper way to use different transitions in voyager?

Open akardas16 opened this issue 1 year ago • 11 comments

What is the proper way to use different transitions in voyager? Below code didn't work for me.

Navigator(HomeScreen) { navigator ->
               if (navigator.lastItem.key == DetailScreen(name = "").key) {
                      FadeTransition(navigator)
                } else {
                        SlideTransitions(navigator)
                    }
                }

akardas16 avatar Aug 26 '23 01:08 akardas16

I've found the best way is to use https://voyager.adriel.cafe/navigation/nested-navigation

Syer10 avatar Aug 26 '23 01:08 Syer10

I've found the best way is to use https://voyager.adriel.cafe/navigation/nested-navigation

If that is the case, It is not possible to use different transitions in same Navigator. Am I right?

akardas16 avatar Aug 26 '23 02:08 akardas16

If that is the case, It is not possible to use different transitions in same Navigator. Am I right?

This might help: https://www.droidcon.com/2022/08/02/painless-typesafe-jetpack-compose-navigation-with-voyager/ You can skip to around 21:36

Ric-AB avatar Sep 12 '23 16:09 Ric-AB

@kihaki do you have a library/repo with this code? The way you did animations and results look great, and I would love to use it

Syer10 avatar Sep 12 '23 23:09 Syer10

Watched the video and loved it, would love to be able to see the repo and play around with it as well

Pixelaters avatar Sep 17 '23 14:09 Pixelaters

The source was published here https://github.com/kihaki/droidcon_2022_voyager

Thanks @kihaki

DevSrSouza avatar Oct 15 '23 18:10 DevSrSouza

@Composable
fun Transition(
    navigator: Navigator,
    modifier: Modifier = Modifier,
    content: ScreenTransitionContent = { it.Content() }
) {
    val transition: AnimatedContentTransitionScope<Screen>.() -> ContentTransform = {
        when {
            navigator.lastEvent == StackEvent.Pop && navigator.lastItem == MyScreen -> {
                scaleIn(
                    initialScale = 0.1f,
                ) togetherWith scaleOut(
                    targetScale = 0.2f
                )
            }
            else ->  // slide 
    }
    ScreenTransition(
        navigator = navigator,
        transition = transition,
        modifier = modifier,
        content = content,
    )
}

Same struggle. You can't detect who invokes navigation when you go back. Problem is when navigator.lastEvent is fired navigator.lastItem returns not "last" but a "current" screen. Need to add to API of navigator.lastEvent property with name like "invoker" which tells from where it was called or add to Navigator that property.

Velord avatar Jan 07 '24 03:01 Velord

+1 it would be really nice if we could define transitions per screen and not per navigator.

Kuglll avatar Jan 07 '24 12:01 Kuglll

AnimatedContentTransitionScope has a initialState and targetState.

DevSrSouza avatar Feb 06 '24 02:02 DevSrSouza

Has anyone found a solution?

kaiyrzhanDE avatar May 21 '24 06:05 kaiyrzhanDE

We have introduce a new experimental api, please check out, validate and give feedbacks. https://voyager.adriel.cafe/transitions-api/#per-screen-transitions-experimental

DevSrSouza avatar Jun 05 '24 13:06 DevSrSouza