Search code examples
androidandroid-fragmentsandroid-animationandroid-transitions

When are captureStartValues and captureEndValues called in Android Transition?


I am animating fragments using custom transition animation. For this, I have subclassed Transition and when Fragment view is created I assign enterTransition and exitTransition using Transition subclasses respectively. I see transition happening but without animations. I debugged it by putting breakpoints in captureStartValues and captureEndValues but it was never called. I wish to understand when exactly these function are called? My start and end values are dynamically calculated and I am not too sure how to pass them to Transition or how should I assign them to a view to make transition capture them?


Solution

  • Answering myself:

    I debugged deeper with Android's own transitions and found out both callbacks captureStartValues and captureEndValues do not happen in one animation. captureStartValues will be called for fragment exit animation captureEndValues will be called for fragment enter animation. So For example:

    incomingFragment.apply {
        this.exitTransition = Slide(Gravity.TOP) // This will use 'captureEndValues' in Slide Transition
    }
    fragmentManager.beginTransation() { ... } // Will invoke the call
    

    The start values of the transition will be view's current position. Although you can set start values in transition by using some computation.