-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NT-204] Manage pledge payment method section #851
Changes from 21 commits
68ef47f
05cb1d2
b00b1d6
b124a24
4786c87
786649e
48ed87c
236fb92
e2f6694
49c7f10
6a10fd5
3d46aa8
576ba5b
438100f
ce8263a
60d5a66
926eeaa
aca4598
41c1d57
90772ea
d1a0c1b
dafbf54
3200e23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,141 @@ | ||||
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 lastFourLabel: UILabel = { UILabel(frame: .zero) }() | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||
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() | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any update on this @justinswart ? Thought we talked about swizzling some swizzlers to make this automatic :) |
||||
} | ||||
|
||||
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.lastFourLabel, 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 | ||||
|> cardExpirationDateLabelStyle | ||||
|
||||
_ = self.lastFourLabel | ||||
|> cardLastFourLabelStyle | ||||
|
||||
_ = self.paymentMethodAdaptableStackView | ||||
|> checkoutAdaptableStackViewStyle( | ||||
self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory | ||||
) | ||||
|> paymentMethodAdaptableStackViewStyle | ||||
|
||||
_ = self.rootStackView | ||||
|> checkoutCardStackViewStyle | ||||
|
||||
_ = self.titleLabel | ||||
|> titleLabelStyle | ||||
} | ||||
|
||||
// MARK: - View model | ||||
|
||||
override func bindViewModel() { | ||||
super.bindViewModel() | ||||
|
||||
self.expirationDateLabel.rac.text = self.viewModel.outputs.expirationDateText | ||||
self.lastFourLabel.rac.text = self.viewModel.outputs.cardNumberTextShortStyle | ||||
|
||||
self.viewModel.outputs.cardImage | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add empty line here to separate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a second thought, would it be worth it adding reactive extension on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good idea. I can create a ticket for that to be done in a different PR. |
||||
.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 | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this being set by the If we're setting this explicitly to prevent from a weird UI jump could we also set height or aspect ratio constraint (just to be safe)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The constraint is being set here so the views are placed correctly in the stackView. Also, the imageView's contentMode is |
||||
) | ||||
]) | ||||
} | ||||
} | ||||
|
||||
// MARK: - Styles | ||||
|
||||
private let cardExpirationDateLabelStyle: LabelStyle = { label in | ||||
label | ||||
|> checkoutTitleLabelStyle | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||
|> \.font .~ UIFont.ksr_caption1().bolded | ||||
|> \.adjustsFontForContentSizeCategory .~ true | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate of
Suggested change
|
||||
|> \.textColor .~ UIColor.ksr_text_dark_grey_500 | ||||
} | ||||
|
||||
private let cardLastFourLabelStyle: LabelStyle = { label in | ||||
label | ||||
|> checkoutTitleLabelStyle | ||||
|> \.font .~ UIFont.ksr_subhead().bolded | ||||
|> \.adjustsFontForContentSizeCategory .~ true | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate of
Suggested change
|
||||
|> \.textColor .~ UIColor.ksr_soft_black | ||||
} | ||||
|
||||
private let paymentMethodAdaptableStackViewStyle: StackViewStyle = { stackView in | ||||
stackView | ||||
|> \.spacing .~ Styles.grid(2) | ||||
} | ||||
|
||||
private let titleLabelStyle: LabelStyle = { label in | ||||
label | ||||
|> \.textColor .~ UIColor.black | ||||
|> \.font .~ UIFont.ksr_subhead().bolded | ||||
|> \.adjustsFontForContentSizeCategory .~ true | ||||
|> \.text %~ { _ in Strings.Payment_method() } | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'll also need to use |
||||
|> \.numberOfLines .~ 0 | ||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,10 @@ final class ManagePledgeViewController: UIViewController { | |
UIImage(in: CGRect(x: 0, y: 0, width: 1, height: 0.5), with: .ksr_dark_grey_400) | ||
}() | ||
|
||
private lazy var paymentMethodView: ManagePledgePaymentMethodView = { | ||
ManagePledgePaymentMethodView(frame: .zero) | ||
}() | ||
|
||
private lazy var rewardReceivedViewController: ManageViewPledgeRewardReceivedViewController = { | ||
ManageViewPledgeRewardReceivedViewController.instantiate() | ||
}() | ||
|
@@ -44,7 +48,7 @@ final class ManagePledgeViewController: UIViewController { | |
|> \.translatesAutoresizingMaskIntoConstraints .~ false | ||
}() | ||
|
||
private let viewModel = ManagePledgeViewModel() | ||
private let viewModel: ManagePledgeViewModelType = ManagePledgeViewModel() | ||
|
||
static func instantiate(with project: Project, reward: Reward) -> ManagePledgeViewController { | ||
let manageViewPledgeVC = ManagePledgeViewController.instantiate() | ||
|
@@ -62,16 +66,7 @@ final class ManagePledgeViewController: UIViewController { | |
?|> \.leftBarButtonItem .~ self.closeButton | ||
?|> \.rightBarButtonItem .~ self.menuButton | ||
|
||
_ = (self.rootScrollView, self.view) | ||
|> ksr_addSubviewToParent() | ||
|> ksr_constrainViewToEdgesInParent() | ||
|
||
_ = (self.rootStackView, self.rootScrollView) | ||
|> ksr_addSubviewToParent() | ||
|> ksr_constrainViewToEdgesInParent() | ||
|
||
self.configureViews() | ||
self.configureChildViewControllers() | ||
self.setupConstraints() | ||
|
||
self.viewModel.inputs.viewDidLoad() | ||
|
@@ -114,7 +109,9 @@ final class ManagePledgeViewController: UIViewController { | |
|
||
self.viewModel.outputs.configurePaymentMethodView | ||
.observeForUI() | ||
.observeValues { _ in } | ||
.observeValues { [weak self] card in | ||
self?.paymentMethodView.configure(with: card) | ||
} | ||
|
||
self.viewModel.outputs.configurePledgeSummaryView | ||
.observeForUI() | ||
|
@@ -165,21 +162,6 @@ final class ManagePledgeViewController: UIViewController { | |
|
||
// MARK: - Configuration | ||
|
||
private func configureChildViewControllers() { | ||
let childViewControllers = [ | ||
self.rewardReceivedViewController | ||
] | ||
|
||
childViewControllers.forEach { viewController in | ||
self.addChild(viewController) | ||
|
||
_ = ([viewController.view], self.rootStackView) | ||
|> ksr_addArrangedSubviewsToStackView() | ||
|
||
viewController.didMove(toParent: self) | ||
} | ||
} | ||
|
||
func configureWith(project: Project, reward: Reward) { | ||
self.viewModel.inputs.configureWith(project, reward: reward) | ||
} | ||
|
@@ -201,7 +183,13 @@ final class ManagePledgeViewController: UIViewController { | |
|> ksr_addSubviewToParent() | ||
|> ksr_constrainViewToEdgesInParent() | ||
|
||
_ = ([self.pledgeSummaryView], self.rootStackView) | ||
let childViews: [UIView] = [ | ||
self.pledgeSummaryView, | ||
self.paymentMethodView, | ||
self.rewardReceivedViewController.view | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to add this not only to view hierarchy but to view-controller hierarchy as we do at other places (this is to ensure proper behavior fo the view-controller when being embedded in a parent VC.
|
||
] | ||
|
||
_ = (childViews, self.rootStackView) | ||
|> ksr_addArrangedSubviewsToStackView() | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also add
// MARK: - Configuration
??