Skip to content

Commit

Permalink
Refactor FXIOS-7700 [v123] Fix Warnings about LegacyResizableButton (#…
Browse files Browse the repository at this point in the history
…18044)

* Fix warnings for instances of LegacyResizableButton for yesButton and make manageCardsButton a subclass of LinkButton.

---------

Co-authored-by: Sophie Amin <samin@mozilla.com>
  • Loading branch information
dataports and dataports committed Jan 9, 2024
1 parent 5b9594d commit 2abc006
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ public struct AccessibilityIdentifiers {
struct RememberCreditCard {
static let rememberCreditCardHeader = "RememberCreditCard.Header"
static let yesButton = "RememberCreditCard.yesButton"
static let manageCardsButton = "RememberCreditCard.manageCardsButton"
static let notNowButton = "RememberCreditCard.notNowButton"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,13 @@ class CreditCardBottomSheetFooterView: UITableViewHeaderFooterView, ReusableCell
static let manageCardsButtonLeadingSpace: CGFloat = 0
static let manageCardsButtonTopSpace: CGFloat = 24
static let manageCardsButtonBottomSpace: CGFloat = 24
static let titleVerticalPadding: CGFloat = 6
static let titleVerticalLongPadding: CGFloat = 20
}

public lazy var manageCardsButton: LegacyResizableButton = .build { button in
button.titleLabel?.font = DefaultDynamicFontHelper.preferredFont(
withTextStyle: .callout,
size: UX.manageCardsButtonFontSize)
button.setTitle(.CreditCard.UpdateCreditCard.ManageCardsButtonTitle, for: .normal)
button.titleLabel?.textAlignment = .left
button.contentHorizontalAlignment = .left
button.titleLabel?.adjustsFontForContentSizeCategory = true
button.accessibilityIdentifier = AccessibilityIdentifiers.RememberCreditCard.yesButton
}
public lazy var manageCardsButton: LinkButton = .build { button in }

override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
contentView.addSubview(manageCardsButton)
setupManageCardsButton()
setupView()
}

Expand All @@ -40,7 +29,19 @@ class CreditCardBottomSheetFooterView: UITableViewHeaderFooterView, ReusableCell

func applyTheme(theme: Theme) {
contentView.backgroundColor = theme.colors.layer1
manageCardsButton.setTitleColor(theme.colors.textAccent, for: .normal)
manageCardsButton.applyTheme(theme: theme)
}

func setupManageCardsButton() {
contentView.addSubview(manageCardsButton)
let buttonViewModel = LinkButtonViewModel(
title: .CreditCard.UpdateCreditCard.ManageCardsButtonTitle,
a11yIdentifier: AccessibilityIdentifiers.RememberCreditCard.manageCardsButton,
fontSize: UX.manageCardsButtonFontSize,
contentHorizontalAlignment: .left
)

manageCardsButton.configure(viewModel: buttonViewModel)
}

private func setupView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,8 @@ class CreditCardBottomSheetViewController: UIViewController,
stack.spacing = UX.buttonsSpacing
}

private lazy var yesButton: LegacyResizableButton = .build { button in
button.titleLabel?.font = DefaultDynamicFontHelper.preferredFont(
withTextStyle: .headline,
size: UX.yesButtonFontSize)
private lazy var yesButton: PrimaryRoundedButton = .build { button in
button.addTarget(self, action: #selector(self.didTapYes), for: .touchUpInside)
button.setTitle(.CreditCard.RememberCreditCard.MainButtonTitle, for: .normal)
button.layer.cornerRadius = UX.yesButtonCornerRadius
button.titleLabel?.adjustsFontForContentSizeCategory = true
button.accessibilityIdentifier = AccessibilityIdentifiers.RememberCreditCard.yesButton
}

private var contentViewHeightConstraint: NSLayoutConstraint!
Expand Down Expand Up @@ -148,7 +141,14 @@ class CreditCardBottomSheetViewController: UIViewController,
func addSubviews() {
if viewModel.state != .selectSavedCard {
buttonsContainerStackView.addArrangedSubview(yesButton)
let buttonViewModel = PrimaryRoundedButtonViewModel(
title: .CreditCard.RememberCreditCard.MainButtonTitle,
a11yIdentifier: AccessibilityIdentifiers.RememberCreditCard.yesButton
)
yesButton.configure(viewModel: buttonViewModel)
yesButton.applyTheme(theme: themeManager.currentTheme)
}

contentView.addSubviews(cardTableView, buttonsContainerStackView)
view.addSubview(contentView)
}
Expand Down Expand Up @@ -354,15 +354,12 @@ class CreditCardBottomSheetViewController: UIViewController,

// MARK: Themable
func applyTheme() {
let currentTheme = themeManager.currentTheme
view.backgroundColor = currentTheme.colors.layer1
yesButton.backgroundColor = currentTheme.colors.actionPrimary
yesButton.setTitleColor(currentTheme.colors.textInverted, for: .normal)
let currentTheme = themeManager.currentTheme.colors
view.backgroundColor = currentTheme.layer1
cardTableView.reloadData()
}

// MARK: Telemetry

fileprivate func sendCreditCardAutofillPromptDismissedTelemetry() {
TelemetryWrapper.recordEvent(category: .action,
method: .close,
Expand Down

0 comments on commit 2abc006

Please sign in to comment.