Skip to content

Commit

Permalink
Feature native checkout applepay button (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scollaco authored and ifbarrera committed Aug 6, 2019
1 parent e0bd6d4 commit e8e4355
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions Kickstarter-iOS/Views/Cells/PledgePaymentMethodsCell.swift
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import KsApi
import Library
import PassKit
import Prelude
import UIKit

final class PledgePaymentMethodsCell: UITableViewCell, ValueCell {
// MARK: - Properties

private let layout: UICollectionViewLayout = {
UICollectionViewFlowLayout()
|> \.scrollDirection .~ .horizontal
}()
private lazy var applePayButton: PKPaymentButton = { PKPaymentButton() }()

private lazy var collectionView: UICollectionView = {
UICollectionView(frame: .zero, collectionViewLayout: self.layout)
|> \.dataSource .~ self
}()

private let layout: UICollectionViewLayout = {
UICollectionViewFlowLayout()
|> \.scrollDirection .~ .horizontal
}()

private lazy var rootStackView: UIStackView = { UIStackView(frame: .zero) }()

private lazy var titleLabel: UILabel = { UILabel(frame: .zero) }()
Expand All @@ -33,15 +36,22 @@ final class PledgePaymentMethodsCell: UITableViewCell, ValueCell {
}

private func configureSubviews() {
_ = self
|> \.accessibilityElements .~ self.subviews

_ = (self.rootStackView, self.contentView)
|> ksr_addSubviewToParent()
|> ksr_constrainViewToEdgesInParent()

_ = ([self.titleLabel, self.collectionView], self.rootStackView)
_ = ([self.applePayButton, self.titleLabel, self.collectionView], self.rootStackView)
|> ksr_addArrangedSubviewsToStackView()

NSLayoutConstraint.activate([
self.applePayButton.heightAnchor.constraint(greaterThanOrEqualToConstant: Styles.minTouchSize.height)
])

self.applePayButton.addTarget(
self,
action: #selector(PledgePaymentMethodsCell.applePayButtonTapped),
for: .touchUpInside
)
}

// MARK: - Styles
Expand All @@ -51,6 +61,10 @@ final class PledgePaymentMethodsCell: UITableViewCell, ValueCell {
_ = self
|> checkoutBackgroundStyle

_ = self.applePayButton
|> roundedStyle(cornerRadius: Styles.grid(2))
|> \.isAccessibilityElement .~ true

_ = self.collectionView
|> \.backgroundColor .~ .white

Expand All @@ -65,11 +79,21 @@ final class PledgePaymentMethodsCell: UITableViewCell, ValueCell {
|> \.textAlignment .~ .center
}

// MARK: - View model

override func bindViewModel() {
super.bindViewModel()
}

// MARK: - Configuration

internal func configureWith(value _: [GraphUserCreditCard]) {}

// MARK: - Actions

@objc private func applePayButtonTapped() {
print("Apple Pay tapped")
}
}

extension PledgePaymentMethodsCell: UICollectionViewDataSource {
Expand Down

0 comments on commit e8e4355

Please sign in to comment.