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

Update animations to use UIViewPropertyAnimator #134

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kylebshr
Copy link

@kylebshr kylebshr commented Feb 21, 2021

Summary

This PR has a couple goals:

  • Update the default behavior of the modal to match iOS system animations
  • Give developers more control over the animations by using the more modern UIViewPropertyAnimator rather than properties that are provided to UIView.animate

Both of these are accomplished by using a UIViewPropertyAnimator for animation transitions. I thought about how to model this for a while, and I think the solution I implemented works best with the current API design of PanModal. I introduced a new function on PanModalPresentable: func makeAnimator() -> UIViewPropertyAnimator. This is a function because UIViewPropertyAnimator is stateful, so a new one should be created for each animation. I avoided adding a delegate method to perform the animations because that is prone to user error, e.g., not calling the completion block. The default implementation creates an animator with the default UISpringTimingParameters, which matches the animation used to present modals in iOS (https://twitter.com/smileyborg/status/745310304481906688).

RE: tests - there weren't any animation tests to improve upon. I'm happy to add some if the maintainers have any thoughts on what to test.

Fixes #133

Default Custom (Spring)
basic spring

Requirements (place an x in each [ ])

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.

  • I've read and agree to the Code of Conduct.

  • I've written tests to cover the new code and functionality included in this PR.

@CLAassistant
Copy link

CLAassistant commented Feb 21, 2021

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ kylebshr
❌ Kyle Bashour


Kyle Bashour seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@kylebshr kylebshr marked this pull request as ready for review February 21, 2021 20:45
@@ -65,4 +65,10 @@ class AlertViewController: UIViewController, PanModalPresentable {
var isUserInteractionEnabled: Bool {
return true
}

func makeAnimator() -> UIViewPropertyAnimator {
let animator = UIViewPropertyAnimator(duration: 0.5, dampingRatio: 0.7, animations: nil)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think notifications are a great place for springy animations, and provided an example of a custom animator there.

@ppamorim
Copy link

I really like this PR. Is this still applicable?

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

Successfully merging this pull request may close these issues.

PanModel should match iOS transitions by default
3 participants