Skip to content

Commit

Permalink
[NT-357][NT-358] Change Payment Method UI (#887)
Browse files Browse the repository at this point in the history
* Updated validation

* Fix snapshot tests, add submitButtonHidden

* Add PledgeAmountSummaryViewController

* Add updateButtonTapped

* Add snapshot test and vm test

* lol

* Remove unused var

* Rename signal, fix payment source ID comparison

* Fix tests

* Fix tests, simplify hiding of shipping location stackview

* Fix snapshots

* Commit the actual snapshots

* Use local var

* [NT-359] Integrate Updating Backing mutation (#893)

* Wire up change payment method to mutation for payment source and Apple Pay

* Remove payment method when backing with Apple Pay and vice versa

* Update tests for apple pay sheet race condition fixes

* Replace zip with simpler signals

* Add Stripe token error test

* Move signals around, improve tests
  • Loading branch information
justinswart committed Oct 16, 2019
1 parent be2137d commit 7de27fa
Show file tree
Hide file tree
Showing 40 changed files with 1,567 additions and 355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ final class ManagePledgeViewController: UIViewController, MessageBannerViewContr

self.viewModel.outputs.goToChangePaymentMethod
.observeForControllerAction()
.observeValues { [weak self] in
self?.goToChangePaymentMethod()
.observeValues { [weak self] project, reward in
self?.goToChangePaymentMethod(project: project, reward: reward)
}

self.viewModel.outputs.goToContactCreator
Expand Down Expand Up @@ -359,8 +359,12 @@ final class ManagePledgeViewController: UIViewController, MessageBannerViewContr
self.navigationController?.pushViewController(cancelPledgeViewController, animated: true)
}

private func goToChangePaymentMethod() {
// TODO:
private func goToChangePaymentMethod(project: Project, reward: Reward) {
let vc = PledgeViewController.instantiate()
vc.configureWith(project: project, reward: reward, refTag: nil, context: .changePaymentMethod)
vc.delegate = self

self.show(vc, sender: nil)
}

private func goToContactCreator() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import KsApi
import Library
import Prelude
import Prelude_UIKit
import UIKit

final class PledgeAmountSummaryViewController: UIViewController {
// MARK: Properties

private lazy var pledgeAmountLabel: UILabel = { UILabel(frame: .zero) }()
private lazy var pledgeAmountStackView: UIStackView = { UIStackView(frame: .zero) }()
private lazy var pledgeLabel: UILabel = { UILabel(frame: .zero) }()
private lazy var rootStackView: UIStackView = { UIStackView(frame: .zero) }()
private lazy var shippingAmountLabel: UILabel = { UILabel(frame: .zero) }()
private lazy var shippingLocationLabel: UILabel = { UILabel(frame: .zero) }()
private lazy var shippingLocationStackView: UIStackView = { UIStackView(frame: .zero) }()

private let viewModel: PledgeAmountSummaryViewModelType = PledgeAmountSummaryViewModel()

// MARK: Life cycle

public func configureWith(_ project: Project) {
self.viewModel.inputs.configureWith(project)
}

override func viewDidLoad() {
super.viewDidLoad()

self.configureSubviews()

self.viewModel.inputs.viewDidLoad()
}

// MARK: Styles

override func bindStyles() {
super.bindStyles()

let isAccessibilityCategory = self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory

_ = self.pledgeAmountStackView
|> checkoutAdaptableStackViewStyle(isAccessibilityCategory)

_ = self.rootStackView
|> rootStackViewStyle

_ = self.shippingLocationStackView
|> checkoutAdaptableStackViewStyle(isAccessibilityCategory)

_ = self.pledgeLabel
|> pledgeLabelStyle

_ = self.pledgeAmountLabel
|> amountLabelStyle

_ = self.shippingLocationLabel
|> shippingLocationLabelStyle

_ = self.shippingAmountLabel
|> amountLabelStyle
}

// MARK: View model

override func bindViewModel() {
super.bindViewModel()

self.pledgeAmountLabel.rac.attributedText = self.viewModel.outputs.pledgeAmountText
self.shippingAmountLabel.rac.attributedText = self.viewModel.outputs.shippingAmountText
self.shippingLocationLabel.rac.text = self.viewModel.outputs.shippingLocationText
self.shippingLocationStackView.rac.hidden = self.viewModel.outputs.shippingLocationStackViewIsHidden
}

// MARK: Functions

private func configureSubviews() {
_ = (self.rootStackView, self.view)
|> ksr_addSubviewToParent()
|> ksr_constrainViewToEdgesInParent()

_ = ([self.pledgeLabel, self.pledgeAmountLabel], self.pledgeAmountStackView)
|> ksr_addArrangedSubviewsToStackView()

_ = ([self.shippingLocationLabel, self.shippingAmountLabel], self.shippingLocationStackView)
|> ksr_addArrangedSubviewsToStackView()

_ = ([
self.pledgeAmountStackView,
self.shippingLocationStackView
], self.rootStackView)
|> ksr_addArrangedSubviewsToStackView()
}
}

// MARK: Styles

private let amountLabelStyle: LabelStyle = { label in
label
|> \.adjustsFontForContentSizeCategory .~ true
|> \.textAlignment .~ NSTextAlignment.right
|> \.isAccessibilityElement .~ true
|> \.minimumScaleFactor .~ 0.75
}

private let pledgeLabelStyle: LabelStyle = { label in
label
|> \.textColor .~ UIColor.ksr_dark_grey_500
|> \.font .~ UIFont.ksr_subhead().bolded
|> \.adjustsFontForContentSizeCategory .~ true
|> \.text %~ { _ in Strings.Pledge() }
}

private let rootStackViewStyle: StackViewStyle = { stackView in
stackView
|> checkoutStackViewStyle
|> \.spacing .~ Styles.grid(3)
}

private let shippingLocationLabelStyle: LabelStyle = { label in
label
|> \.textColor .~ UIColor.ksr_dark_grey_500
|> \.font .~ UIFont.ksr_subhead().bolded
|> \.adjustsFontForContentSizeCategory .~ true
|> \.numberOfLines .~ 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ protocol PledgePaymentMethodsViewControllerDelegate: AnyObject {
_ viewController: PledgePaymentMethodsViewController,
didSelectCreditCard paymentSourceId: String
)

func pledgePaymentMethodsViewControllerDidTapPledgeButton(
_ viewController: PledgePaymentMethodsViewController
)
}

final class PledgePaymentMethodsViewController: UIViewController {
Expand All @@ -25,10 +21,8 @@ final class PledgePaymentMethodsViewController: UIViewController {
private lazy var cardsStackView: UIStackView = { UIStackView(frame: .zero) }()
internal weak var delegate: PledgePaymentMethodsViewControllerDelegate?
internal weak var messageDisplayingDelegate: PledgeViewControllerMessageDisplaying?
private lazy var pledgeButton: UIButton = { UIButton.init(type: .custom) }()
private lazy var rootStackView: UIStackView = { UIStackView(frame: .zero) }()
private lazy var scrollView: UIScrollView = { UIScrollView(frame: .zero) }()
private lazy var scrollViewContainer: UIView = { UIView(frame: .zero) }()
private lazy var spacer: UIView = { UIView(frame: .zero) }()
private lazy var titleLabel: UILabel = { UILabel(frame: .zero) }()
private let viewModel: PledgePaymentMethodsViewModelType = PledgePaymentMethodsViewModel()
Expand All @@ -45,18 +39,15 @@ final class PledgePaymentMethodsViewController: UIViewController {
}

private func configureSubviews() {
_ = (self.scrollView, self.scrollViewContainer)
_ = (self.scrollView, self.view)
|> ksr_addSubviewToParent()
|> ksr_constrainViewToEdgesInParent()

_ = (self.cardsStackView, self.scrollView)
|> ksr_addSubviewToParent()
|> ksr_constrainViewToEdgesInParent()

_ = (
[self.applePayButton, self.spacer, self.titleLabel, self.scrollViewContainer, self.pledgeButton],
self.rootStackView
)
_ = ([self.applePayButton, self.spacer, self.titleLabel, self.scrollView], self.rootStackView)
|> ksr_addArrangedSubviewsToStackView()

_ = (self.rootStackView, self.view)
Expand All @@ -68,19 +59,12 @@ final class PledgePaymentMethodsViewController: UIViewController {
action: #selector(PledgePaymentMethodsViewController.applePayButtonTapped),
for: .touchUpInside
)

self.pledgeButton.addTarget(
self,
action: #selector(PledgePaymentMethodsViewController.pledgeButtonTapped),
for: .touchUpInside
)
}

private func setupConstraints() {
NSLayoutConstraint.activate([
self.cardsStackView.heightAnchor.constraint(equalTo: self.scrollViewContainer.heightAnchor),
self.applePayButton.heightAnchor.constraint(greaterThanOrEqualToConstant: Styles.minTouchSize.height),
self.pledgeButton.heightAnchor.constraint(greaterThanOrEqualToConstant: Styles.minTouchSize.height)
self.scrollView.heightAnchor.constraint(equalTo: self.cardsStackView.heightAnchor),
self.applePayButton.heightAnchor.constraint(greaterThanOrEqualToConstant: Styles.minTouchSize.height)
])
}

Expand All @@ -97,10 +81,6 @@ final class PledgePaymentMethodsViewController: UIViewController {
_ = self.applePayButton
|> applePayButtonStyle

_ = self.pledgeButton
|> greenButtonStyle
|> UIButton.lens.title(for: .normal) %~ { _ in Strings.Pledge() }

_ = self.scrollView
|> checkoutBackgroundStyle

Expand Down Expand Up @@ -146,14 +126,6 @@ final class PledgePaymentMethodsViewController: UIViewController {
self.delegate?.pledgePaymentMethodsViewController(self, didSelectCreditCard: paymentSourceId)
}

self.viewModel.outputs.notifyDelegatePledgeButtonTapped
.observeForUI()
.observeValues { [weak self] in
guard let self = self else { return }

self.delegate?.pledgePaymentMethodsViewControllerDidTapPledgeButton(self)
}

self.viewModel.outputs.updateSelectedCreditCard
.observeForUI()
.observeValues { [weak self] card in
Expand All @@ -167,7 +139,6 @@ final class PledgePaymentMethodsViewController: UIViewController {
}

self.applePayButton.rac.hidden = self.viewModel.outputs.applePayButtonHidden
self.pledgeButton.rac.enabled = self.viewModel.outputs.pledgeButtonEnabled
}

// MARK: - Configuration
Expand All @@ -182,20 +153,12 @@ final class PledgePaymentMethodsViewController: UIViewController {
self.viewModel.inputs.configureWith(pledgePaymentMethodsValue)
}

// MARK: - Accessors
// MARK: - Actions

@objc private func applePayButtonTapped() {
self.viewModel.inputs.applePayButtonTapped()
}

@objc private func pledgeButtonTapped() {
self.viewModel.inputs.pledgeButtonTapped()
}

func updatePledgeButton(_ enabled: Bool) {
self.viewModel.inputs.updatePledgeButtonEnabled(isEnabled: enabled)
}

// MARK: - Functions

private func goToAddNewCard(intent: AddNewCardIntent, project: Project) {
Expand Down
Loading

0 comments on commit 7de27fa

Please sign in to comment.