Skip to content
Draft
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 StripeCore/StripeCore/Source/UI/UIFont+Stripe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}()
Expand All @@ -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
Expand Down Expand Up @@ -164,6 +165,7 @@ class CardScanningView: UIView {
}

init(theme: ElementsAppearance) {
self.theme = theme
super.init(frame: .zero)
self.setupBlurView()

Expand Down Expand Up @@ -268,7 +270,7 @@ class CardScanningView: UIView {
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
fatalError("init(coder:) has not been implemented")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

AU Becs and its mandate was previously not covered by snapshot tests.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ...mentSheetSnapshotTests/[email protected]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mandate font is now bigger because it matches the custom font style

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading