Skip to content

Commit

Permalink
Fix ActivityIndicator layout issues (#991)
Browse files Browse the repository at this point in the history
* Increase the default content hugging priority for ActivityIndicator

* Disable implicit animations during content layer layout

* Remove unnecesary content hugging priority override
  • Loading branch information
ramont-stripe authored Apr 13, 2022
1 parent afc62a7 commit 626f591
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 0 additions & 3 deletions Stripe/LinkEmailElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class LinkEmailElement: Element {
private let activityIndicator: ActivityIndicator = {
// TODO: Consider adding the activity indicator to TextFieldView
let activityIndicator = ActivityIndicator(size: .medium)
activityIndicator.setContentHuggingPriority(.required, for: .horizontal)
activityIndicator.setContentCompressionResistancePriority(.required, for: .horizontal)
return activityIndicator
}()
Expand Down Expand Up @@ -89,6 +88,4 @@ extension LinkEmailElement: ElementDelegate {
func continueToNextField(element: Element) {
delegate?.continueToNextField(element: self)
}


}
11 changes: 11 additions & 0 deletions StripeUICore/StripeUICore/Source/Controls/ActivityIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ import UIKit
super.init(frame: .zero)
layer.addSublayer(contentLayer)

setContentHuggingPriority(.defaultHigh, for: .horizontal)
setContentHuggingPriority(.defaultHigh, for: .vertical)

updateVisibility()
updatecolor()

Expand Down Expand Up @@ -144,8 +147,16 @@ import UIKit

public override func layoutSubviews() {
super.layoutSubviews()

CATransaction.begin()
// `bounds` and `position` are both animatable. Disable actions to turn off
// implicit animations when updating them.
CATransaction.setDisableActions(true)

contentLayer.bounds = CGRect(origin: .zero, size: intrinsicContentSize)
contentLayer.position = CGPoint(x: bounds.midX, y: bounds.midY)

CATransaction.commit()
}

public override func willMove(toWindow newWindow: UIWindow?) {
Expand Down

0 comments on commit 626f591

Please sign in to comment.