Skip to content

Commit

Permalink
make rows tappable and changed chevron label
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceqin-stripe committed Nov 19, 2024
1 parent f4282ce commit 6fdfad6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2470,7 +2470,7 @@ class PaymentSheetDefaultSPMUITests: PaymentSheetUITestCase {
app.buttons["View more"].waitForExistenceAndTap()
app.buttons["Edit"].waitForExistenceAndTap()

XCTAssertEqual(app.buttons.matching(identifier: "Update card").count, 2)
XCTAssertEqual(app.buttons.matching(identifier: "chevron").count, 2)
}
func testDefaultSPMNavigationFlagOff() {
var settings = PaymentSheetTestPlaygroundSettings.defaultValues()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class SavedPaymentMethodRowButton: UIView {
}

rowButton.isSelected = isSelected
rowButton.isEnabled = !isEditing
rowButton.isEnabled = !isEditing || alternateUpdatePaymentMethodNavigation
circleView.isHidden = !isSelected
chevronButton.isHidden = !canUpdate || !alternateUpdatePaymentMethodNavigation
updateButton.isHidden = !canUpdate || alternateUpdatePaymentMethodNavigation
Expand Down Expand Up @@ -127,11 +127,7 @@ final class SavedPaymentMethodRowButton: UIView {
}()

private lazy var rowButton: RowButton = {
let button: RowButton = .makeForSavedPaymentMethod(paymentMethod: paymentMethod, appearance: appearance, rightAccessoryView: stackView) { [weak self] _ in
guard let self else { return }
state = .selected
delegate?.didSelectButton(self, with: paymentMethod)
}
let button: RowButton = .makeForSavedPaymentMethod(paymentMethod: paymentMethod, appearance: appearance, rightAccessoryView: stackView, didTap: handleRowButtonTapped)

return button
}()
Expand Down Expand Up @@ -160,4 +156,13 @@ final class SavedPaymentMethodRowButton: UIView {
delegate?.didSelectRemoveButton(self, with: paymentMethod)
}

@objc private func handleRowButtonTapped(rowButton: RowButton) {
if alternateUpdatePaymentMethodNavigation && isEditing {
delegate?.didSelectUpdateButton(self, with: paymentMethod)
}
else {
state = .selected
delegate?.didSelectButton(self, with: paymentMethod)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,19 @@ extension VerticalSavedPaymentMethodsViewController: SavedPaymentMethodRowButton
}

func didSelectUpdateButton(_ button: SavedPaymentMethodRowButton, with paymentMethod: STPPaymentMethod) {
let updateViewController = UpdateCardViewController(paymentMethod: paymentMethod,
removeSavedPaymentMethodMessage: configuration.removeSavedPaymentMethodMessage,
appearance: configuration.appearance,
hostedSurface: .paymentSheet,
canRemoveCard: canRemovePaymentMethods,
isTestMode: configuration.apiClient.isTestmode,
cardBrandFilter: configuration.cardBrandFilter)

updateViewController.delegate = self
self.updateViewController = updateViewController
self.bottomSheetController?.pushContentViewController(updateViewController)
if paymentMethod.type == .card {
let updateViewController = UpdateCardViewController(paymentMethod: paymentMethod,
removeSavedPaymentMethodMessage: configuration.removeSavedPaymentMethodMessage,
appearance: configuration.appearance,
hostedSurface: .paymentSheet,
canRemoveCard: canRemovePaymentMethods,
isTestMode: configuration.apiClient.isTestmode,
cardBrandFilter: configuration.cardBrandFilter)

updateViewController.delegate = self
self.updateViewController = updateViewController
self.bottomSheetController?.pushContentViewController(updateViewController)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension RowButton {
case .viewMore:
return .Localized.view_more
case .update:
return .Localized.update_card
return nil
}
}

Expand All @@ -41,9 +41,7 @@ extension RowButton {

private var label: UILabel {
let label = UILabel()
if accessoryType != .update {
label.text = accessoryType.text
}
label.text = accessoryType.text
label.font = appearance.scaledFont(for: appearance.font.base.medium, style: .footnote, maximumPointSize: 20)
if #available(iOS 15.0, *) {
label.minimumContentSizeCategory = .large
Expand Down Expand Up @@ -89,6 +87,9 @@ extension RowButton {

accessibilityLabel = accessoryType.text
accessibilityIdentifier = accessoryType.text
if accessoryType == .update {
accessibilityIdentifier = "chevron"
}
accessibilityTraits = [.button]
isAccessibilityElement = true

Expand Down

0 comments on commit 6fdfad6

Please sign in to comment.