Skip to content
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

Feature native checkout applepay button #742

Merged
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)
Scollaco marked this conversation as resolved.
Show resolved Hide resolved
|> 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() {
Scollaco marked this conversation as resolved.
Show resolved Hide resolved
print("Apple Pay tapped")
}
}

extension PledgePaymentMethodsCell: UICollectionViewDataSource {
Expand Down