Android Navigation Component pop to transition issue

前端 未结 2 871
广开言路
广开言路 2020-12-29 08:05

I have 2 actions

Action1

 

        
2条回答
  •  滥情空心
    2020-12-29 08:32

    I ended up overriding onCreateAnimation in the fragment that calls navigate. This exemple shows how to navigate through nested nav graphs by ID and replace the pop exit animation (or popExitAnim) conditionnally.

    override fun onCreateAnimation(transit: Int, enter: Boolean, nextAnim: Int): Animation? {
        val navController = findNavController()
        val graph = navController.graph.findNode(R.id.onboardingGraph) as NavGraph
        val dest = graph.findNode(R.id.confirmationFragment)
        if (!enter && dest != null && navController.currentDestination?.id == dest.id) {
            return AnimationUtils.loadAnimation(requireContext(), R.anim.slide_out_left)
        }
        return super.onCreateAnimation(transit, enter, nextAnim)
    }
    

    Note that this particular situation is partly due to the directional nature of slide animations.

提交回复
热议问题