-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NT-204] Manage pledge payment method section (#851)
* Added ManagePledgePaymentMethodView, created PaymentSource type * Added ManagePledgePaymentMethodView, created PaymentSource type * Fixed CreditCard decoding bug / View styling / Added view to ManageViewPledgeViewController * Fixed / incremented tests * Code cleanup / Added missing tests * Swiftformat * Alphabetization * Fixed margins of pledge summary view / Updated configureVIews function * Set numberOfLines to 0 for title label * Renamed stackView / Used PledgeCreditCardViewModel to bind card infos * Added explicit object type while defining styles * Added closure variable name / removed unecessary style wrapper * Removed line that broke VoiceOver * Reverted commented out line * Swiftformat * [NT-204] Additional fixes (#861) * Rename label and styles * Refactor styles * Add vc to parent properly * Flatten the style
- Loading branch information
Showing
14 changed files
with
301 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
Kickstarter-iOS/Views/Controllers/ManagePledgePaymentMethodView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import KsApi | ||
import Library | ||
import Prelude | ||
import UIKit | ||
|
||
final class ManagePledgePaymentMethodView: UIView { | ||
// MARK: - Properties | ||
|
||
private lazy var cardImageView: UIImageView = { UIImageView(frame: .zero) }() | ||
private lazy var cardLabelsStackView: UIStackView = { UIStackView(frame: .zero) }() | ||
private lazy var expirationDateLabel: UILabel = { UILabel(frame: .zero) }() | ||
private lazy var lastFourDigitsLabel: UILabel = { UILabel(frame: .zero) }() | ||
private lazy var paymentMethodAdaptableStackView: UIStackView = { UIStackView(frame: .zero) }() | ||
private lazy var rootStackView: UIStackView = { UIStackView(frame: .zero) }() | ||
private lazy var titleLabel: UILabel = { UILabel(frame: .zero) }() | ||
|
||
private let viewModel: PledgeCreditCardViewModelType = PledgeCreditCardViewModel() | ||
|
||
// MARK: - Lifecycle | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
|
||
self.configureViews() | ||
self.setupConstraints() | ||
self.bindViewModel() | ||
} | ||
|
||
required init?(coder _: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// MARK: - Configuration | ||
|
||
public func configure(with card: GraphUserCreditCard.CreditCard) { | ||
self.viewModel.inputs.configureWith(value: card) | ||
} | ||
|
||
private func configureViews() { | ||
_ = ([self.lastFourDigitsLabel, self.expirationDateLabel], self.cardLabelsStackView) | ||
|> ksr_addArrangedSubviewsToStackView() | ||
|
||
_ = ([self.cardImageView, self.cardLabelsStackView], self.paymentMethodAdaptableStackView) | ||
|> ksr_addArrangedSubviewsToStackView() | ||
|
||
_ = ([self.titleLabel, self.paymentMethodAdaptableStackView], self.rootStackView) | ||
|> ksr_addArrangedSubviewsToStackView() | ||
|
||
_ = (self.rootStackView, self) | ||
|> ksr_addSubviewToParent() | ||
|> ksr_constrainViewToEdgesInParent() | ||
} | ||
|
||
// MARK: - Styles | ||
|
||
override func bindStyles() { | ||
super.bindStyles() | ||
|
||
_ = self.cardImageView | ||
|> cardImageViewStyle | ||
|
||
_ = self.cardLabelsStackView | ||
|> verticalStackViewStyle | ||
|
||
_ = self.expirationDateLabel | ||
|> expirationDateLabelStyle | ||
|
||
_ = self.lastFourDigitsLabel | ||
|> lastFourDigitsLabelStyle | ||
|
||
_ = self.paymentMethodAdaptableStackView | ||
|> checkoutAdaptableStackViewStyle( | ||
self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory | ||
) | ||
|> paymentMethodAdaptableStackViewStyle | ||
|
||
_ = self.rootStackView | ||
|> checkoutCardStackViewStyle | ||
|
||
_ = self.titleLabel | ||
|> checkoutTitleLabelStyle | ||
|> \.text %~ { _ in Strings.Payment_method() } | ||
} | ||
|
||
// MARK: - View model | ||
|
||
override func bindViewModel() { | ||
super.bindViewModel() | ||
|
||
self.expirationDateLabel.rac.text = self.viewModel.outputs.expirationDateText | ||
self.lastFourDigitsLabel.rac.text = self.viewModel.outputs.cardNumberTextShortStyle | ||
|
||
self.viewModel.outputs.cardImage | ||
.observeForUI() | ||
.observeValues { [weak self] image in | ||
_ = self?.cardImageView | ||
?|> \.image .~ image | ||
} | ||
} | ||
|
||
// MARK: - Functions | ||
|
||
private func setupConstraints() { | ||
NSLayoutConstraint.activate([ | ||
self.cardImageView.widthAnchor.constraint( | ||
equalToConstant: CheckoutConstants.PaymentSource.ImageView.width | ||
) | ||
]) | ||
} | ||
} | ||
|
||
// MARK: - Styles | ||
|
||
private let expirationDateLabelStyle: LabelStyle = { label in | ||
label | ||
|> \.adjustsFontForContentSizeCategory .~ true | ||
|> \.font .~ UIFont.ksr_caption1().bolded | ||
|> \.numberOfLines .~ 0 | ||
|> \.textColor .~ UIColor.ksr_text_dark_grey_500 | ||
} | ||
|
||
private let lastFourDigitsLabelStyle: LabelStyle = { label in | ||
label | ||
|> \.adjustsFontForContentSizeCategory .~ true | ||
|> \.font .~ UIFont.ksr_subhead().bolded | ||
|> \.numberOfLines .~ 0 | ||
|> \.textColor .~ UIColor.ksr_soft_black | ||
} | ||
|
||
private let paymentMethodAdaptableStackViewStyle: StackViewStyle = { stackView in | ||
stackView | ||
|> \.spacing .~ Styles.grid(2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.