-
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.
💲[Native Checkout] Prepare reward pill collection view UI (#757)
* Extract classNameWithoutModule to shared functions * Update collection view convenience functions * Update table view convenience functions * Add pill collection view, cell, layout and data source * Style pill cell * Add pill collection to reward cell * Format code * Update font * Fix a bug caused by a merge gone wrong * Make adding / removing pill collection view controller more robust * Refactor pill collection view * Use consistent way to register collection view cell * Remove nilling out delegate
- Loading branch information
1 parent
2daf162
commit c9bf1fd
Showing
9 changed files
with
311 additions
and
50 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
Kickstarter-iOS/DataSources/PillCollectionViewDataSource.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,22 @@ | ||
import Foundation | ||
import Library | ||
import UIKit | ||
|
||
final class PillCollectionViewDataSource: ValueCellDataSource { | ||
func load(_ values: [String]) { | ||
self.set( | ||
values: values, | ||
cellClass: PillCell.self, | ||
inSection: 0 | ||
) | ||
} | ||
|
||
override func configureCell(collectionCell cell: UICollectionViewCell, withValue value: Any) { | ||
switch (cell, value) { | ||
case let (cell as PillCell, value as String): | ||
cell.configureWith(value: value) | ||
default: | ||
assertionFailure("Unrecognized (cell, value) combo.") | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Kickstarter-iOS/DataSources/PillCollectionViewDataSourceTests.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,18 @@ | ||
@testable import Kickstarter_Framework | ||
import Prelude | ||
import XCTest | ||
|
||
final class PillCollectionViewDataSourceTests: XCTestCase { | ||
private let dataSource = PillCollectionViewDataSource() | ||
private let collectionView = UICollectionView( | ||
frame: .zero, | ||
collectionViewLayout: UICollectionViewFlowLayout() | ||
) | ||
|
||
func testLoadValues() { | ||
self.dataSource.load(["one", "two", "three"]) | ||
|
||
XCTAssertEqual(1, self.dataSource.numberOfSections(in: self.collectionView)) | ||
XCTAssertEqual(3, self.dataSource.collectionView(self.collectionView, numberOfItemsInSection: 0)) | ||
} | ||
} |
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,63 @@ | ||
import Library | ||
import Prelude | ||
import UIKit | ||
|
||
final class PillCell: UICollectionViewCell, ValueCell { | ||
// MARK: - Properties | ||
|
||
private(set) lazy var label = { | ||
UILabel(frame: .zero) | ||
|> \.translatesAutoresizingMaskIntoConstraints .~ false | ||
}() | ||
|
||
// MARK: - Lifecycle | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
|
||
_ = self.contentView | ||
|> \.layoutMargins .~ UIEdgeInsets(topBottom: Styles.gridHalf(2), leftRight: Styles.gridHalf(3)) | ||
|
||
_ = (self.label, self.contentView) | ||
|> ksr_addSubviewToParent() | ||
|> ksr_constrainViewToMarginsInParent() | ||
} | ||
|
||
required init?(coder _: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// MARK: - Styles | ||
|
||
override func bindStyles() { | ||
super.bindStyles() | ||
|
||
_ = self.contentView | ||
|> contentViewStyle | ||
|
||
_ = self.label | ||
|> labelStyle | ||
} | ||
|
||
// MARK: - Configuration | ||
|
||
func configureWith(value: String) { | ||
_ = self.label | ||
|> \.text .~ value | ||
} | ||
} | ||
|
||
// MARK: - Styles | ||
|
||
private let contentViewStyle: ViewStyle = { view in | ||
view | ||
|> checkoutRoundedCornersStyle | ||
|> \.backgroundColor .~ UIColor.ksr_green_500.withAlphaComponent(0.06) | ||
} | ||
|
||
private let labelStyle: LabelStyle = { label in | ||
label | ||
|> \.font .~ UIFont.ksr_footnote().bolded | ||
|> \.numberOfLines .~ 0 | ||
|> \.textColor .~ UIColor.ksr_green_500 | ||
} |
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.