diff --git a/Example/PaymentSheet Example/PaymentSheetUITest/PaymentSheetLPMUITest.swift b/Example/PaymentSheet Example/PaymentSheetUITest/PaymentSheetLPMUITest.swift index cd287ea18674..3625ec484c71 100644 --- a/Example/PaymentSheet Example/PaymentSheetUITest/PaymentSheetLPMUITest.swift +++ b/Example/PaymentSheet Example/PaymentSheetUITest/PaymentSheetLPMUITest.swift @@ -173,6 +173,7 @@ class PaymentSheetStandardLPMUITwoTests: PaymentSheetStandardLPMUICase { app.buttons["+ Add"].waitForExistenceAndTap() tapPaymentMethod("SEPA Debit") try! fillSepaData(app, iban: "AT611904300234573201", tapCheckboxWithText: "Save this account for future Example, Inc. payments") + app.swipeUp() app.buttons["Continue"].tap() app.buttons["Confirm"].waitForExistenceAndTap() XCTAssertTrue(app.staticTexts["Success!"].waitForExistence(timeout: 10.0)) diff --git a/StripeCore/StripeCore/Source/UI/UIFont+Stripe.swift b/StripeCore/StripeCore/Source/UI/UIFont+Stripe.swift index 2ba8c557c827..9d2d51fd0fb2 100644 --- a/StripeCore/StripeCore/Source/UI/UIFont+Stripe.swift +++ b/StripeCore/StripeCore/Source/UI/UIFont+Stripe.swift @@ -16,6 +16,7 @@ import UIKit /// https://developer.apple.com/documentation/uikit/uifont/scaling_fonts_automatically private static let defaultSizeCategory: UIContentSizeCategory = .large + /// - Note: for Payment Sheet/Element contexts, use PaymentSheet.Appearance.scaledFont instead. This method uses the system font instead of a user's custom font. public static func preferredFont( forTextStyle style: TextStyle, weight: Weight, @@ -36,6 +37,7 @@ import UIKit /// - Parameters: /// - style: The style used to determine the font's size. /// - weight: The weight to apply to the font. + /// - Note: for Payment Sheet/Element contexts, use PaymentSheet.Appearance.scaledFont instead. This method uses the system font instead of a user's custom font. public func withPreferredSize( forTextStyle style: TextStyle, weight: Weight? = nil diff --git a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/USBankAccount/InstantDebitsPaymentMethodElement.swift b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/USBankAccount/InstantDebitsPaymentMethodElement.swift index 3ffda7ff4c43..4ec55199397b 100644 --- a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/USBankAccount/InstantDebitsPaymentMethodElement.swift +++ b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/USBankAccount/InstantDebitsPaymentMethodElement.swift @@ -63,7 +63,7 @@ final class InstantDebitsPaymentMethodElement: ContainerElement { string.addAttributes( [ .paragraphStyle: style, - .font: UIFont.preferredFont(forTextStyle: .footnote), + .font: theme.fonts.footnote, .foregroundColor: theme.colors.secondaryText, ], range: NSRange(location: 0, length: string.length) @@ -390,7 +390,7 @@ private extension PaymentMethodIncentive { formattedString.addAttributes( [ .paragraphStyle: style, - .font: UIFont.preferredFont(forTextStyle: .footnote), + .font: appearance.fonts.footnote, .foregroundColor: appearance.colors.secondaryText, ], range: NSRange(location: 0, length: formattedString.length) diff --git a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/Views/AUBECSMandate.swift b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/Views/AUBECSMandate.swift index 2cbbaeb97b5b..409584cd3c0f 100644 --- a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/Views/AUBECSMandate.swift +++ b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/Views/AUBECSMandate.swift @@ -27,10 +27,8 @@ final class AUBECSLegalTermsView: UIView { let textView = UITextView() textView.isScrollEnabled = false textView.isEditable = false - textView.font = theme.fonts.caption textView.backgroundColor = .clear textView.attributedText = formattedLegalText() - textView.textColor = theme.colors.secondaryText textView.linkTextAttributes = [.foregroundColor: theme.colors.primary] textView.textContainerInset = .zero textView.textContainer.lineFragmentPadding = 0 @@ -52,7 +50,7 @@ final class AUBECSLegalTermsView: UIView { #if !os(visionOS) override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) - textView.font = .preferredFont(forTextStyle: .caption1) + textView.font = theme.fonts.caption } #endif @@ -62,7 +60,15 @@ final class AUBECSLegalTermsView: UIView { "Legal text shown when using AUBECS." ) let string = String(format: template, configuration.merchantDisplayName) - return STPStringUtils.applyLinksToString(template: string, links: links) + let formattedString = STPStringUtils.applyLinksToString(template: string, links: links) + formattedString.addAttributes( + [ + .font: theme.fonts.caption, + .foregroundColor: theme.colors.secondaryText, + ], + range: formattedString.extent + ) + return formattedString } } diff --git a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/Views/CardScanningView.swift b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/Views/CardScanningView.swift index c3322bdfcef5..9a3357e4c134 100644 --- a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/Views/CardScanningView.swift +++ b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/Views/CardScanningView.swift @@ -43,6 +43,7 @@ class CardScanningView: UIView { } } + private let theme: ElementsAppearance private lazy var cardScanner: STPCardScanner? = nil private static let cardSizeRatio: CGFloat = 2.125 / 3.370 // ID-1 card size (in inches) @@ -75,7 +76,7 @@ class CardScanningView: UIView { let label = UILabel() label.text = "" label.textAlignment = .center - label.font = .preferredFont(forTextStyle: .headline) + label.font = theme.fonts.sectionHeader label.translatesAutoresizingMaskIntoConstraints = false return label }() @@ -85,7 +86,7 @@ class CardScanningView: UIView { label.text = String.Localized.allow_camera_access label.textAlignment = .center label.numberOfLines = 3 - label.font = .preferredFont(forTextStyle: .subheadline) + label.font = theme.fonts.subheadline label.translatesAutoresizingMaskIntoConstraints = false label.textColor = .white label.isHidden = true @@ -164,6 +165,7 @@ class CardScanningView: UIView { } init(theme: ElementsAppearance) { + self.theme = theme super.init(frame: .zero) self.setupBlurView() @@ -268,7 +270,7 @@ class CardScanningView: UIView { } required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) + fatalError("init(coder:) has not been implemented") } } diff --git a/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetFormFactorySnapshotTest.swift b/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetFormFactorySnapshotTest.swift index 61cd44e11861..2ba8de4af18d 100644 --- a/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetFormFactorySnapshotTest.swift +++ b/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetFormFactorySnapshotTest.swift @@ -411,6 +411,20 @@ final class PaymentSheetFormFactorySnapshotTest: STPSnapshotTestCase { XCTAssertTrue(formElement.validationState.isValid) } + func testLpm_AUBecs_customFont() { + var configuration = PaymentSheet.Configuration() + configuration.appearance.font.base = UIFont(name: "Courier", size: 16)! + configuration.appearance.colors.textSecondary = .red + let factory = factory( + for: .AUBECSDebit, + configuration: configuration + ) + let formElement = factory.make() + let view = formElement.view + view.autosizeHeight(width: 375) + STPSnapshotVerifyView(view) + } + func testEPM_subtitle() { let configuration = PaymentSheet.Configuration() let factory = factory(for: .card, configuration: configuration) diff --git a/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetSnapshotTests.swift b/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetSnapshotTests.swift index 59a4e4f2972d..f7e7ee2e11a4 100644 --- a/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetSnapshotTests.swift +++ b/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetSnapshotTests.swift @@ -633,8 +633,14 @@ class PaymentSheetSnapshotTests: STPSnapshotTestCase { stubCustomers() stubConsumerSession() + // Instant debits includes unqiue labels. Test with custom font to ensure it renders correctly. + var appearance = PaymentSheet.Appearance() + appearance.font.sizeScaleFactor = 1.15 + appearance.font.base = UIFont(name: "AvenirNext-Regular", size: UIFont.labelFontSize)! + preparePaymentSheet( currency: "usd", + appearance: appearance, override_payment_methods_types: ["link"], automaticPaymentMethods: false, useLink: false diff --git a/Tests/ReferenceImages_64/StripePaymentSheetTests.PaymentSheetFormFactorySnapshotTest/testLpm_AUBecs_customFont@3x.png b/Tests/ReferenceImages_64/StripePaymentSheetTests.PaymentSheetFormFactorySnapshotTest/testLpm_AUBecs_customFont@3x.png new file mode 100644 index 000000000000..b62bfb4b56fa Binary files /dev/null and b/Tests/ReferenceImages_64/StripePaymentSheetTests.PaymentSheetFormFactorySnapshotTest/testLpm_AUBecs_customFont@3x.png differ diff --git a/Tests/ReferenceImages_64/StripePaymentSheetTests.PaymentSheetSnapshotTests/testPaymentSheet_LPM_InstantDebits_only_promotion@3x.png b/Tests/ReferenceImages_64/StripePaymentSheetTests.PaymentSheetSnapshotTests/testPaymentSheet_LPM_InstantDebits_only_promotion@3x.png index fb6aea10f184..6d6f957ad14c 100644 Binary files a/Tests/ReferenceImages_64/StripePaymentSheetTests.PaymentSheetSnapshotTests/testPaymentSheet_LPM_InstantDebits_only_promotion@3x.png and b/Tests/ReferenceImages_64/StripePaymentSheetTests.PaymentSheetSnapshotTests/testPaymentSheet_LPM_InstantDebits_only_promotion@3x.png differ diff --git a/Tests/ReferenceImages_64/StripePaymentSheetTests.PaymentSheetVerticalViewControllerSnapshotTest/testPromoBadgeInFormTitle@3x.png b/Tests/ReferenceImages_64/StripePaymentSheetTests.PaymentSheetVerticalViewControllerSnapshotTest/testPromoBadgeInFormTitle@3x.png index 3264c6055540..9e47624d394f 100644 Binary files a/Tests/ReferenceImages_64/StripePaymentSheetTests.PaymentSheetVerticalViewControllerSnapshotTest/testPromoBadgeInFormTitle@3x.png and b/Tests/ReferenceImages_64/StripePaymentSheetTests.PaymentSheetVerticalViewControllerSnapshotTest/testPromoBadgeInFormTitle@3x.png differ