Adding listener for shared element callback not changing view visibility

331 views Asked by At

I am using shared element transition between two activities. The second activity is comprised of view pager containing fragments. I want to make further changes when shared element transition ends. This is the callback:

setEnterSharedElementCallback(
        object : SharedElementCallback() {
            override fun onMapSharedElements(
                names: MutableList<String>,
                sharedElements: MutableMap<String, View>
            ) {
                val keySharedElementView = sharedElements[videoPath[currentPosition]]
                if (keySharedElementView != null) {
                    Log.i("KSEV", "Not Null")
                    ViewCompat.animate(keySharedElementView)
                        .setListener(object : ViewPropertyAnimatorListenerAdapter() {
                            override fun onAnimationEnd(view: View?) {
                                super.onAnimationEnd(view)
                                Log.i("KSEV","Ended")
                                runOnUiThread { k 
                                   videoThumb.visibility = GONE
                                    if (videoThumb.visibility == GONE) {
                                        Log.i("SEV", "GONE")
                                    }
                                 }
                            }
                        }).start()
                }
            }
        })

Last Log statement GONE is printed. But view is still visible on screen. How to change its visibility?

1

There are 1 answers

2
Rahul Shukla On

Your code seems good except that you haven't started the animation yet, hence no onAnimationEnd() callback.

Modify your code as follows:

ViewCompat.animate(keySharedElementView)
                        .setListener(object : ViewPropertyAnimatorListenerAdapter() {
                            override fun onAnimationEnd(view: View?) {
                                super.onAnimationEnd(view)
                                Log.i("KSEV","Ended")
                            }
                        }).setDuration(250).start()