mikescamell / shared-element-transitions

Source code for a blog post series on Shared Element Transitions in Android
http://bit.ly/sharedelementtransitions
MIT License
284 stars 73 forks source link

Return transition doesn't work #15

Open MHKalantarian opened 5 years ago

MHKalantarian commented 5 years ago

I have nested fragments inside a fragment and it works perfect when I enter the second fragment. But when I pop back stack to return to the first fragment it just normally returns without any animation or move or anything, like no shared elements ever defined. Also I'm using cardview for my recycler items layout.

razaghimahdi commented 3 years ago

i know it's too late but maybe this be useful, so just add this to fragmentA(which list is there):

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

         postponeEnterTransition()
        val parentView = view.parent as ViewGroup
        parentView.viewTreeObserver
            .addOnPreDrawListener(object : ViewTreeObserver.OnPreDrawListener {
                override fun onPreDraw(): Boolean {
                    parentView.viewTreeObserver.removeOnPreDrawListener(this)
                     startPostponedEnterTransition()
                    return true
                }
            })
        super.onViewCreated(view, savedInstanceState)

    }