Deep link and animation using Android Navigation component
J

1

5

I'm trying to implement a forgot password flow. What I'd like to do is to handle the received email, which contains a link to a forgot password web page, inside the app.

Using the Navigation component I created a deep link, which opens the right fragment (the one with the password field). So I'm able to change the password. Clicking on back, I return to the login screen, which is the start point of my navigation graph.

Everything works as expected, except for the animations. When I create an action between destination, I'm able to assign enter/exit/popenter/popexit animations, but with deep link I don't create any action, so when I push back, I reach the expected fragment but no animation is played.

I tried to play a bit with the code, but no results, and I cannot find any possible solution in the docs.

I tried to create some actions in my navigation graph (there are 4 different options right clicking on a destination:

  • to destination (the most common and the one I usually use)
  • to self (I don't understand the purpose of this)
  • return to sourc (I don't understand the purpose of this)
  • global

None of them seems to solve my problem. Ideas? Thanks in advance.

Jackknife answered 2/3, 2020 at 17:14 Comment(0)
G
10

You can find in the NavController

public void navigate(@NonNull Uri deepLink, @Nullable NavOptions navOptions) {
    navigate(deepLink, navOptions, null);
}

In NavOptions set your animations in the same way like in an action:

val navOptions =
    NavOptions.Builder()
        .setPopUpTo(
            R.id.nav_graph_main,
            false
        )
        .setEnterAnim(R.anim.slide_in_right)
        .setExitAnim(R.anim.slide_out_left)
        .setPopEnterAnim(R.anim.slide_in_left)
        .setPopExitAnim(R.anim.slide_out_right)
        .build()
Guanidine answered 16/4, 2020 at 20:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.