Skip to content

Commit

Permalink
Fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-stripe committed Jan 29, 2025
1 parent 8754db5 commit 620b8a5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,22 +380,24 @@ class EmbeddedPaymentMethodsView: UIView {
}
}()
let selection: Selection = .saved(paymentMethod: savedPaymentMethod)
let savedPaymentMethodButton = RowButton.makeForSavedPaymentMethod(paymentMethod: savedPaymentMethod,
appearance: rowButtonAppearance,
rightAccessoryView: accessoryButton,
isEmbedded: true,
didTap: { [weak self] _ in
CustomerPaymentOption.setDefaultPaymentMethod(
.stripeId(savedPaymentMethod.stripeId),
forCustomer: self?.customer?.id
)
self?.didTap(selection: selection)
})
let savedPaymentMethodButton = RowButton.makeForSavedPaymentMethod(
paymentMethod: savedPaymentMethod,
appearance: rowButtonAppearance,
rightAccessoryView: accessoryButton,
isEmbedded: true,
didTap: { [weak self] _ in
CustomerPaymentOption.setDefaultPaymentMethod(
.stripeId(savedPaymentMethod.stripeId),
forCustomer: self?.customer?.id
)
self?.didTap(selection: selection)
}
)
return savedPaymentMethodButton
}

func makePaymentMethodRowButton(paymentMethodType: PaymentSheet.PaymentMethodType, savedPaymentMethods: [STPPaymentMethod]) -> RowButton {
// We always add a hidden accessory button ("Change >") so we can un-hide if needed
// We always add a hidden accessory button ("Change >") so we can show/hide it easily
let accessoryButton = RowButton.RightAccessoryButton(
accessoryType: appearance.embeddedPaymentElement.row.style == .flatWithCheckmark ? .changeWithChevron : .change,
appearance: appearance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,13 @@ class RowButton: UIView {
imageView.widthAnchor.constraint(equalToConstant: 24),
]

let isSavedPMRow = rightAccessoryView != nil
if isFlatWithCheckmarkStyle, isSavedPMRow {
labelsStackView.setCustomSpacing(8, after: label)
if isFlatWithCheckmarkStyle, let rightAccessoryView, !rightAccessoryView.isHidden {
// In flat_with_checkmark, we need additional vertical space around the View More / Change accessory view.
if sublabel.isHidden {
labelsStackView.setCustomSpacing(8, after: sublabel)
} else {
labelsStackView.setCustomSpacing(8, after: label)
}
imageViewConstraints.append(imageView.centerYAnchor.constraint(equalTo: label.centerYAnchor))
} else {
imageViewConstraints.append(imageView.centerYAnchor.constraint(equalTo: centerYAnchor))
Expand Down Expand Up @@ -351,7 +355,7 @@ class RowButton: UIView {
return
}
// Don't do this if we *are* the tallest variant; otherwise we'll infinite loop!
guard sublabel?.text?.isEmpty ?? true else {
guard sublabel.text?.isEmpty ?? true else {
return
}
heightConstraint = heightAnchor.constraint(equalToConstant: Self.calculateTallestHeight(appearance: appearance, isEmbedded: isEmbedded))
Expand Down Expand Up @@ -442,7 +446,7 @@ extension RowButton {
) -> RowButton {
let imageView = PaymentMethodTypeImageView(paymentMethodType: paymentMethodType, backgroundColor: appearance.colors.componentBackground)
imageView.contentMode = .scaleAspectFit

// Special case "New card" vs "Card" title
let text: String = {
if hasSavedCard && paymentMethodType == .stripe(.card) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ enum VerticalPaymentMethodListSelection: Equatable, Hashable {
return false
}
}

func hash(into hasher: inout Hasher) {
switch self {
case .new(let paymentMethodType):
Expand Down

0 comments on commit 620b8a5

Please sign in to comment.