FR: Add callback to ComponentAnimator


#1

Hi, would be nice if we could pass a callback into the animations so we can get notified when they’re complete.

thx


#2

ComponentAnimator is a ChangeBroadcaster so if you make your object a ChangeListener, then you can write:

animator.addChangeListener (&myListener);

before you start your animation. Then, in your ChangeListener subclass you can do something like:

void changeListenerCallback (ChangeBroadcaster* source) override
{
    if (source == &animator)
    {
        if (animator.isAnimating (&myComponent))
        {
            // animation of myComponent started
            animationInProgress = true;
        }
        else if (animationInProgress && ! animator.isAnimating (&myComponent))
        {
            // stopped animation
            animationInProgress = false;
        }
            
    }
}

this will also handle cases when the animation gets cancelled.


#3

ah, nice. thx. Not come across ChangeBroadcaster before.