Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected animator state in completion block #34

Open
juliensagot opened this issue Apr 13, 2023 · 0 comments
Open

Unexpected animator state in completion block #34

juliensagot opened this issue Apr 13, 2023 · 0 comments

Comments

@juliensagot
Copy link

juliensagot commented Apr 13, 2023

Hi 👋

The state of an animator is being updated after calling its completion block, resulting in being incorrect in said completion block.
This is major issue when you want to share a completion block with multiple animators with different settling times, and execute some logic after all animators have completed.

For example:

let firstAnimator = SpringAnimator<CGFloat>(...)
let secondAnimator = SpringAnimator<CGRect>(...)

let sharedCompletion = {
    guard case .ended = firstAnimator.state, case .ended = secondAnimator.state  // Will never be satisfied
    else { return }
    print("Both animations are finished.")
}

firstAnimator.completion = { completion in
    guard case .finished = completion else { return }
    // (firstAnimator.state == .ended) → false 😭
    sharedCompletion()
}

secondAnimator.completion = { completion in
    guard case .finished = completion else { return }
    // (secondAnimator.state == .ended) → false 😭
    sharedCompletion()
}

I understand that you don't accept contributions yet so I haven't opened a pull request, but if you change your mind, I don't mind opening one!
I forked the project and fixed the issue in the meantime.

Thanks again for this delightful animation engine, I love it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant