Skip to content

Commit 1d09daf

Browse files
committed
Added UITextField model and provider. Fixed header provider for collection.
1 parent c6cdc89 commit 1d09daf

7 files changed

+17
-9
lines changed

Sources/SPDiffable/Collection/DataSource/AppleCollectionDiffableDataSource.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AppleCollectionDiffableDataSource: UICollectionViewDiffableDataSource<SPDi
3232
headerFooterProvider: SupplementaryViewProvider?
3333
) {
3434
super.init(collectionView: collectionView, cellProvider: cellProvider)
35-
self.supplementaryViewProvider = supplementaryViewProvider
35+
self.supplementaryViewProvider = headerFooterProvider
3636
}
3737

3838
// MARK: - Wrappers

Sources/SPDiffable/Collection/DataSource/SPDiffableCollectionDataSource+HeaderFooterProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extension SPDiffableCollectionDataSource {
3232
self.clouser = clouser
3333
}
3434

35-
public typealias Clouser = (_ collectionView: UICollectionView, _ section: Int, _ item: SPDiffableItem) -> UICollectionReusableView?
35+
public typealias Clouser = (_ collectionView: UICollectionView, _ kind: String, _ indexPath: IndexPath, _ item: SPDiffableItem) -> UICollectionReusableView?
3636
}
3737
}
3838

Sources/SPDiffable/Collection/DataSource/SPDiffableCollectionDataSource.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ open class SPDiffableCollectionDataSource: NSObject, SPDiffableDataSourceInterfa
3636
collectionView: UICollectionView,
3737
cellProviders: [CellProvider],
3838
headerFooterProviders: [HeaderFooterProvider],
39-
headerAsFirstCell: Bool = true
39+
headerAsFirstCell: Bool
4040
) {
4141
self.headerAsFirstCell = headerAsFirstCell
4242
self.collectionView = collectionView
@@ -71,12 +71,12 @@ open class SPDiffableCollectionDataSource: NSObject, SPDiffableDataSourceInterfa
7171
switch elementKind {
7272
case UICollectionView.elementKindSectionHeader:
7373
guard let headerItem = section.header else { continue }
74-
if let view = provider.clouser(collectionView, sectionIndex, headerItem) {
74+
if let view = provider.clouser(collectionView, elementKind, indexPath, headerItem) {
7575
return view
7676
}
7777
case UICollectionView.elementKindSectionFooter:
7878
guard let footerItem = section.footer else { continue }
79-
if let view = provider.clouser(collectionView, sectionIndex, footerItem) {
79+
if let view = provider.clouser(collectionView, elementKind, indexPath, footerItem) {
8080
return view
8181
}
8282
default:

Sources/SPDiffable/Collection/SPDiffableCollectionController.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ open class SPDiffableCollectionController: UICollectionViewController {
3838
open func configureDiffable(
3939
sections: [SPDiffableSection],
4040
cellProviders: [SPDiffableCollectionDataSource.CellProvider],
41-
headerFooterProviders: [SPDiffableCollectionDataSource.HeaderFooterProvider] = []
41+
headerFooterProviders: [SPDiffableCollectionDataSource.HeaderFooterProvider] = [],
42+
headerAsFirstCell: Bool
4243
) {
4344
diffableDataSource = SPDiffableCollectionDataSource(
4445
collectionView: collectionView,
4546
cellProviders: cellProviders,
46-
headerFooterProviders: headerFooterProviders
47+
headerFooterProviders: headerFooterProviders,
48+
headerAsFirstCell: headerAsFirstCell
4749
)
4850
diffableDataSource?.set(sections, animated: false)
4951
}

Sources/SPDiffable/Collection/SPDiffableCollectionView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ open class SPDiffableCollectionView: UICollectionView, UICollectionViewDelegate
4848
open func configureDiffable(
4949
sections: [SPDiffableSection],
5050
cellProviders: [SPDiffableCollectionDataSource.CellProvider],
51-
headerFooterProviders: [SPDiffableCollectionDataSource.HeaderFooterProvider] = []
51+
headerFooterProviders: [SPDiffableCollectionDataSource.HeaderFooterProvider] = [],
52+
headerAsFirstCell: Bool
5253
) {
5354
diffableDataSource = SPDiffableCollectionDataSource(
5455
collectionView: self,
5556
cellProviders: cellProviders,
56-
headerFooterProviders: headerFooterProviders
57+
headerFooterProviders: headerFooterProviders,
58+
headerAsFirstCell: headerAsFirstCell
5759
)
5860
diffableDataSource?.set(sections, animated: false)
5961
}

Sources/SPDiffable/Table/DataSource/SPDiffableTableDataSource+CellProvider.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ extension SPDiffableTableDataSource {
124124
cell.textField.keyboardType = item.keyboardType
125125
cell.textField.autocapitalizationType = item.autocapitalizationType
126126
cell.textField.delegate = item.delegate
127+
cell.textField.clearButtonMode = item.clearButtonMode
127128
cell.accessoryView = .none
128129
cell.selectionStyle = .none
129130
return cell

Sources/SPDiffable/Table/Models/SPDiffableTableRowTextField.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ open class SPDiffableTableRowTextField: SPDiffableItem {
2828
open var autocorrectionType: UITextAutocorrectionType
2929
open var keyboardType: UIKeyboardType
3030
open var autocapitalizationType: UITextAutocapitalizationType
31+
open var clearButtonMode: UITextField.ViewMode
3132
open weak var delegate: UITextFieldDelegate?
3233

3334
public init(
@@ -37,6 +38,7 @@ open class SPDiffableTableRowTextField: SPDiffableItem {
3738
autocorrectionType: UITextAutocorrectionType,
3839
keyboardType: UIKeyboardType,
3940
autocapitalizationType: UITextAutocapitalizationType,
41+
clearButtonMode: UITextField.ViewMode,
4042
delegate: UITextFieldDelegate?
4143
) {
4244
self.text = text
@@ -45,6 +47,7 @@ open class SPDiffableTableRowTextField: SPDiffableItem {
4547
self.autocorrectionType = autocorrectionType
4648
self.keyboardType = keyboardType
4749
self.autocapitalizationType = autocapitalizationType
50+
self.clearButtonMode = clearButtonMode
4851
super.init(id: id)
4952
}
5053
}

0 commit comments

Comments
 (0)