Skip to content

Commit

Permalink
Address Element - fix some visual glitches (#1362)
Browse files Browse the repository at this point in the history
* Fixes checkbox having ambigous layout - this occasionally caused bad layouts when 'Billing address is same as shipping' is toggled after PaymentSheet is dismissed and reappears

* Rewrite animateAlongsideKeyboard to use UIViewPropertyAnimator instead of UIView.animate

* Fix curve

* Update snapshot tests

* Improve transition animation to autocomplete
  • Loading branch information
yuki-stripe authored Aug 11, 2022
1 parent 2c2cb35 commit b8d03e7
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions Stripe/AutoCompleteViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class AutoCompleteViewController: UIViewController {
return
}

view.layoutIfNeeded() // Ensures the view is laid out before animating
let keyboardViewEndFrame = view.convert(keyboardScreenEndFrame, from: view.window)
let keyboardInViewHeight = view.safeAreaLayoutGuide.layoutFrame.intersection(keyboardViewEndFrame).height
if notification.name == UIResponder.keyboardWillHideNotification {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,21 @@ import UIKit
) {
let userInfo = notification.userInfo

guard let duration = userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber else {
guard let duration = userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double else {
animations()
return
}

// Get keyboard animation info
// TODO(ramont): extract animation curve from `keyboardAnimationCurveUserInfoKey`
// (see: http://www.openradar.me/42609976)
let curve = UIView.AnimationCurve.easeOut

UIView.animate(
withDuration: duration.doubleValue,
delay: 0,
options: [.curveEaseOut],
animations: animations
)
// Animate the container above the keyboard
// Note: We prefer UIViewPropertyAnimator over UIView.animate because it handles consecutive animation calls better. Sometimes this happens when one text field resigns and another immediately becomes first responder.
let animator = UIViewPropertyAnimator(duration: duration, curve: curve) {
animations()
}
animator.startAnimation()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ import UIKit
addSubview(checkbox)
addSubview(stackView)

let minimizeHeight = stackView.heightAnchor.constraint(equalTo: heightAnchor)
minimizeHeight.priority = .defaultLow
NSLayoutConstraint.activate([
// Checkbox
checkboxAlignmentConstraint,
Expand All @@ -183,7 +185,8 @@ import UIKit
stackView.topAnchor.constraint(greaterThanOrEqualTo: topAnchor),
stackView.bottomAnchor.constraint(lessThanOrEqualTo: bottomAnchor),
stackView.leadingAnchor.constraint(equalTo: checkbox.trailingAnchor, constant: 6),
stackView.trailingAnchor.constraint(equalTo: trailingAnchor)
stackView.trailingAnchor.constraint(equalTo: trailingAnchor),
minimizeHeight
])
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b8d03e7

Please sign in to comment.