How to know when Shared Element Transition ends

后端 未结 5 531
不知归路
不知归路 2020-12-14 15:00

I am working with Shared Element Transitions between activities. The transition is working fine but I want to know when the shared element transition ends so th

5条回答
  •  攒了一身酷
    2020-12-14 15:49

    I was struggling to do this in Kotlin using the navigation component but managed to get it working with this

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        setAndPostponeEnterAnimation()
        _binding = PokemonDetailFragmentBinding.inflate(inflater, container, false)
        setInsets()
        handleNavigationArgs()
        return binding.root
    }
    
    private fun setAndPostponeEnterAnimation() {
        postponeEnterTransition()
        sharedElementEnterTransition = TransitionInflater.from(context)
            .inflateTransition(R.transition.shared_element_transition)
        addSharedElementListener()
    }
    
    private fun addSharedElementListener() {
        (sharedElementEnterTransition as TransitionSet).addListener((object :
            TransitionListenerAdapter() {
            override fun onTransitionEnd(transition: Transition) {
                super.onTransitionEnd(transition)
                createRevealAnimation()
            }
        }))
    }
    

    so I can wait for the shared transition to finish before starting a new animation

提交回复
热议问题