Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Example/Example/Components/ComponentsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
let badge2 = BadgeView(colorScheme: .dynamic(lightPalette: .darkMono, darkPalette: .lightMono))
badge.widthAnchor.constraint(equalToConstant: 64).isActive = true

let badgeStack = UIStackView(arrangedSubviews: [badge,badge2, UIView()])

Check warning on line 162 in Example/Example/Components/ComponentsViewController.swift

View workflow job for this annotation

GitHub Actions / Build and Test

There should be no space before and one after any comma (comma)
stack.addArrangedSubview(badgeStack)
let lockup = LockupView(colorScheme: .dynamic(lightPalette: .lightMono, darkPalette: .darkMono))
lockup.widthAnchor.constraint(equalToConstant: 64).isActive = true
Expand Down Expand Up @@ -215,6 +215,8 @@
priceBreakdown3.delegate = self
priceBreakdown3.logoColorScheme = .dynamic(lightPalette: .darkMono, darkPalette: .lightMono)
stack.addArrangedSubview(priceBreakdown3)
let b = BadgeView(colorScheme: .dynamic(lightPalette: .alt, darkPalette: .darkMono))
stack.addArrangedSubview(b)
}

let stackConstraints = [
Expand Down
5 changes: 4 additions & 1 deletion Sources/Afterpay/Views/BadgeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import UIKit
public class BadgeView: AfterpayLogo {
override public init(colorScheme: ColorScheme = .static(.default)) {
if Afterpay.isCashAppAfterpayRegion {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This may read a little better than running the same isCashAppAfterpayRegion check twice.

Suggested change
if Afterpay.isCashAppAfterpayRegion {
if Afterpay.isCashAppAfterpayRegion {
self.isHidden = true
#if DEBUG
assertionFailure("Cash App Afterpay compact badge is not supported")
#endif
}
super.init(colorScheme: colorScheme)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yes I agree, but self must first be init'd before we can set it to hidden

assertionFailure("Cash App Afterpay badge is not supported")
#if DEBUG
assertionFailure("Cash App Afterpay compact badge is not supported")
#endif
}
super.init(colorScheme: colorScheme)
if Afterpay.isCashAppAfterpayRegion { self.isHidden = true }
}

required init?(coder: NSCoder) {
Expand Down
5 changes: 4 additions & 1 deletion Sources/Afterpay/Views/CompactBadgeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import UIKit
public class CompactBadgeView: AfterpayLogo {
override public init(colorScheme: ColorScheme = .static(.default)) {
if Afterpay.isCashAppAfterpayRegion {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same for this view

assertionFailure("Cash App Afterpay compact badge is not supported")
#if DEBUG
assertionFailure("Cash App Afterpay compact badge is not supported")
#endif
}
super.init(colorScheme: colorScheme)
if Afterpay.isCashAppAfterpayRegion { self.isHidden = true }
}

required init?(coder: NSCoder) {
Expand Down
20 changes: 9 additions & 11 deletions Sources/Afterpay/Views/LogoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,15 @@ public class AfterpayLogo: UIView {
deactivateConstraints()

let color = getImageColor()
image = AfterpayAssetProvider.image(named: getImageName(brand: brand.details.lowerCaseName, color: color))

ratio = image!.size.height / image!.size.width

imageView.image = image
imageView.translatesAutoresizingMaskIntoConstraints = false

addSubview(imageView)

setImageViewConstraints()
setupConstraints()
if let image = AfterpayAssetProvider.image(named: getImageName(brand: brand.details.lowerCaseName, color: color)) {
self.image = image
ratio = image.size.height / image.size.width
imageView.image = image
imageView.translatesAutoresizingMaskIntoConstraints = false
addSubview(imageView)
setImageViewConstraints()
setupConstraints()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should the other constraints added in setupConstraints still be added if there is no image? What does this view render like with no image?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Currently, since we use attributes in the image to calculate the constraints (the ratio) we shouldn't setup constraints unless the image exists. Could be changed to use a more modern layout method

}
}

internal func setImageViewConstraints() {
Expand Down