Skip to content

Commit

Permalink
Make PromoBadgeView respect appearance API
Browse files Browse the repository at this point in the history
  • Loading branch information
tillh-stripe committed Nov 22, 2024
1 parent 8ea9ae4 commit b718c81
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ extension PaymentMethodTypeCollectionView {
}()
private lazy var promoBadge: PromoBadgeView = {
let font = appearance.scaledFont(for: appearance.font.base.medium, style: .footnote, maximumPointSize: 20)
return PromoBadgeView(font: font, tinyMode: true)
return PromoBadgeView(appearance: appearance, tinyMode: true)
}()
private lazy var shadowRoundedRectangle: ShadowedRoundedRectangle = {
return ShadowedRoundedRectangle(appearance: appearance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ class RowButton: UIView {
}
if let promoText {
self.promoBadge = PromoBadgeView(
font: appearance.scaledFont(
for: appearance.font.base.medium,
style: .subheadline,
maximumPointSize: 25
),
appearance: appearance,
tinyMode: false,
text: promoText
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,52 @@

import UIKit

@_spi(STP) import StripeUICore

class PromoBadgeView: UIView {

private let labelBackground = UIView()
private let label = UILabel()
private let tinyMode: Bool
private let labelBackground: UIView
private let label: UILabel

convenience init(
appearance: PaymentSheet.Appearance,
tinyMode: Bool,
text: String? = nil
) {
let backgroundColor = appearance.primaryButton.successBackgroundColor
let foregroundColor = appearance.primaryButton.successTextColor ?? appearance.primaryButton.textColor ?? backgroundColor.contrastingColor

self.init(
font: appearance.scaledFont(
for: appearance.font.base.medium,
style: tinyMode ? .footnote : .subheadline,
maximumPointSize: tinyMode ? 20 : 25
),
backgroundColor: backgroundColor,
foregroundColor: foregroundColor,
cornerRadius: appearance.cornerRadius,
tinyMode: tinyMode,
text: text
)
}

init(
private init(
font: UIFont,
tinyMode: Bool = false,
backgroundColor: UIColor,
foregroundColor: UIColor,
cornerRadius: CGFloat,
tinyMode: Bool,
text: String? = nil
) {
self.tinyMode = tinyMode
let labelBackground = UIView()
labelBackground.backgroundColor = backgroundColor
labelBackground.layer.cornerRadius = cornerRadius
self.labelBackground = labelBackground

let label = UILabel()
label.textColor = foregroundColor
self.label = label

super.init(frame: .zero)
setupView(font: font, tinyMode: tinyMode)

Expand All @@ -39,10 +73,6 @@ class PromoBadgeView: UIView {
labelBackground.translatesAutoresizingMaskIntoConstraints = false
addSubview(labelBackground)

// TODO(tillh-stripe) Revisit this
labelBackground.backgroundColor = UIColor(red: 48/255, green: 177/255, blue: 48/255, alpha: 1)
labelBackground.layer.cornerRadius = tinyMode ? 4 : 8

let verticalSpacing: CGFloat = tinyMode ? 0 : 2
let horizontalSpacing: CGFloat = tinyMode ? 4 : 8
labelBackground.layoutMargins = UIEdgeInsets(
Expand Down Expand Up @@ -75,10 +105,9 @@ class PromoBadgeView: UIView {
}

private func formatPromoText(_ text: String) -> String {
// We have limited screen real estate, so we only show the "Get" prefix in some cases
// We have limited screen real estate, so we only show the "Get" prefix in English
let isEnglish = Locale.current.isEnglishLanguage
let showFullText = isEnglish && !tinyMode
return showFullText ? "Get \(text)" : text
return isEnglish ? "Get \(text)" : text
}
}

Expand Down
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.

0 comments on commit b718c81

Please sign in to comment.