Skip to content

Commit fd8e63f

Browse files
committed
Change order in default cell providers. Reorder files struct. Update readme.
1 parent 3e4ed20 commit fd8e63f

24 files changed

Lines changed: 181 additions & 116 deletions

Example/Controllers/DiffableTableController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class DiffableTableController: SPDiffableTableController, SPDiffableTableMediato
1313
override func viewDidLoad() {
1414
super.viewDidLoad()
1515
diffableDataSource?.mediator = self
16-
setCellProviders(SPDiffableTableCellProviders.default, sections: content)
16+
setCellProviders([SPDiffableTableCellProviders.default], sections: content)
1717
}
1818

1919
var content: [SPDiffableSection] {

Example/Controllers/SideBarController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class SidebarController: SPDiffableSideBarController {
55

66
override func viewDidLoad() {
77
super.viewDidLoad()
8-
setCellProviders(SPDiffableCollectionCellProviders.sideBar, sections: content)
8+
setCellProviders([SPDiffableCollectionCellProviders.sideBar], sections: content)
99
}
1010

1111
enum Section: String {

Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ In class available ready-use cell providers for menu item and header section. Fo
183183
```swift
184184
override func viewDidLoad() {
185185
super.viewDidLoad()
186-
setCellProviders(SPDiffableCollectionCellProviders.sideBar, sections: content)
186+
setCellProviders([SPDiffableCollectionCellProviders.sideBar], sections: content)
187187
}
188188
```
189189

@@ -228,7 +228,7 @@ let section = SPDiffableSection(
228228
You init cell model and pass action, choose selection style and other. As you see, model describe native table cell. Next, you need set cell provider, but it also already available, for get it call `SPDiffableTableController.defaultCellProvider`.
229229

230230
```swift
231-
setCellProviders(SPDiffableTableCellProviders.default, sections: [section])
231+
setCellProviders([SPDiffableTableCellProviders.default], sections: [section])
232232
```
233233

234234
Now project's models automatically converting to cell. No need any additional work. That all code.

SPDiffable.xcodeproj/project.pbxproj

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,29 @@
162162
path = App;
163163
sourceTree = "<group>";
164164
};
165+
F483DE6624F6780E00B5B727 /* CellProvider */ = {
166+
isa = PBXGroup;
167+
children = (
168+
OBJ_14 /* Models */,
169+
F4920A6824F447D6007F7EE9 /* SPDiffableTableCellProviders.swift */,
170+
F4920A6B24F44834007F7EE9 /* SPDiffableCollectionCellProviders.swift */,
171+
);
172+
path = CellProvider;
173+
sourceTree = "<group>";
174+
};
175+
F483DE6724F67A0000B5B727 /* DataSource */ = {
176+
isa = PBXGroup;
177+
children = (
178+
OBJ_37 /* SPDiffableTableMediator.swift */,
179+
OBJ_36 /* SPDiffableTableDataSource.swift */,
180+
OBJ_11 /* SPDiffableCollectionDataSource.swift */,
181+
);
182+
path = DataSource;
183+
sourceTree = "<group>";
184+
};
165185
OBJ_14 /* Models */ = {
166186
isa = PBXGroup;
167187
children = (
168-
OBJ_23 /* Table */,
169-
OBJ_15 /* Collection */,
170188
OBJ_19 /* SPDiffableItem.swift */,
171189
F4920A6324F3BFFA007F7EE9 /* SPDiffableWrapperItem.swift */,
172190
OBJ_20 /* SPDiffableSection.swift */,
@@ -176,17 +194,17 @@
176194
path = Models;
177195
sourceTree = "<group>";
178196
};
179-
OBJ_15 /* Collection */ = {
197+
OBJ_15 /* Models */ = {
180198
isa = PBXGroup;
181199
children = (
182200
OBJ_16 /* SPDiffableSideBarButton.swift */,
183201
OBJ_17 /* SPDiffableSideBarHeader.swift */,
184202
OBJ_18 /* SPDiffableSideBarItem.swift */,
185203
);
186-
path = Collection;
204+
path = Models;
187205
sourceTree = "<group>";
188206
};
189-
OBJ_23 /* Table */ = {
207+
OBJ_23 /* Models */ = {
190208
isa = PBXGroup;
191209
children = (
192210
OBJ_24 /* SPDiffableTableRow.swift */,
@@ -195,17 +213,15 @@
195213
OBJ_27 /* SPDiffableTableRowSubtitle.swift */,
196214
OBJ_28 /* SPDiffableTableRowSwitch.swift */,
197215
);
198-
path = Table;
216+
path = Models;
199217
sourceTree = "<group>";
200218
};
201219
OBJ_29 /* Table */ = {
202220
isa = PBXGroup;
203221
children = (
222+
OBJ_23 /* Models */,
204223
OBJ_30 /* Cells */,
205224
OBJ_35 /* SPDiffableTableController.swift */,
206-
OBJ_36 /* SPDiffableTableDataSource.swift */,
207-
OBJ_37 /* SPDiffableTableMediator.swift */,
208-
F4920A6824F447D6007F7EE9 /* SPDiffableTableCellProviders.swift */,
209225
);
210226
path = Table;
211227
sourceTree = "<group>";
@@ -273,8 +289,9 @@
273289
OBJ_8 /* SPDiffable */ = {
274290
isa = PBXGroup;
275291
children = (
292+
F483DE6724F67A0000B5B727 /* DataSource */,
293+
F483DE6624F6780E00B5B727 /* CellProvider */,
276294
OBJ_9 /* Collection */,
277-
OBJ_14 /* Models */,
278295
OBJ_29 /* Table */,
279296
);
280297
name = SPDiffable;
@@ -284,9 +301,8 @@
284301
OBJ_9 /* Collection */ = {
285302
isa = PBXGroup;
286303
children = (
287-
F4920A6B24F44834007F7EE9 /* SPDiffableCollectionCellProviders.swift */,
304+
OBJ_15 /* Models */,
288305
OBJ_10 /* SPDiffableCollectionController.swift */,
289-
OBJ_11 /* SPDiffableCollectionDataSource.swift */,
290306
OBJ_12 /* SPDiffableSideBarButtonCollectionViewListCell.swift */,
291307
OBJ_13 /* SPDiffableSideBarController.swift */,
292308
);
File renamed without changes.

Sources/SPDiffable/Models/SPDiffableSection.swift renamed to Sources/SPDiffable/CellProvider/Models/SPDiffableSection.swift

File renamed without changes.

Sources/SPDiffable/Models/SPDiffableSnapshot.swift renamed to Sources/SPDiffable/CellProvider/Models/SPDiffableSnapshot.swift

File renamed without changes.

Sources/SPDiffable/Models/SPDiffableTextHeaderFooter.swift renamed to Sources/SPDiffable/CellProvider/Models/SPDiffableTextHeaderFooter.swift

File renamed without changes.

Sources/SPDiffable/Models/SPDiffableWrapperItem.swift renamed to Sources/SPDiffable/CellProvider/Models/SPDiffableWrapperItem.swift

File renamed without changes.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import UIKit
2+
3+
public enum SPDiffableCollectionCellProviders {
4+
5+
/**
6+
Defaults cell provider, which can help you doing side bar faster.
7+
You can do your providers and ise its with more flexible.
8+
*/
9+
@available(iOS 14, *)
10+
public static var sideBar: SPDiffableCollectionCellProvider {
11+
let cellProvider: SPDiffableCollectionCellProvider = { (collectionView, indexPath, item) -> UICollectionViewCell? in
12+
let providers = [sideBarItem, sideBarButton, sideBarHeader]
13+
for provider in providers {
14+
if let cell = provider(collectionView, indexPath, item) {
15+
return cell
16+
}
17+
}
18+
return nil
19+
}
20+
return cellProvider
21+
}
22+
23+
@available(iOS 14, *)
24+
public static var sideBarItem: SPDiffableCollectionCellProvider {
25+
let cellProvider: SPDiffableCollectionCellProvider = { (collectionView, indexPath, item) -> UICollectionViewCell? in
26+
guard let item = item as? SPDiffableSideBarItem else { return nil }
27+
let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, SPDiffableSideBarItem> { (cell, indexPath, item) in
28+
var content = UIListContentConfiguration.sidebarCell()
29+
content.text = item.title
30+
content.image = item.image
31+
cell.contentConfiguration = content
32+
cell.accessories = item.accessories
33+
}
34+
return collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: item)
35+
}
36+
return cellProvider
37+
}
38+
39+
@available(iOS 14, *)
40+
public static var sideBarButton: SPDiffableCollectionCellProvider {
41+
let cellProvider: SPDiffableCollectionCellProvider = { (collectionView, indexPath, item) -> UICollectionViewCell? in
42+
guard let item = item as? SPDiffableSideBarButton else { return nil }
43+
let cellRegistration = UICollectionView.CellRegistration<SPDiffableSideBarButtonCollectionViewListCell, SPDiffableSideBarButton> { (cell, indexPath, item) in
44+
cell.updateWithItem(item)
45+
cell.accessories = item.accessories
46+
}
47+
return collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: item)
48+
}
49+
return cellProvider
50+
}
51+
52+
@available(iOS 14, *)
53+
public static var sideBarHeader: SPDiffableCollectionCellProvider {
54+
let cellProvider: SPDiffableCollectionCellProvider = { (collectionView, indexPath, item) -> UICollectionViewCell? in
55+
guard let item = item as? SPDiffableSideBarHeader else { return nil }
56+
let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, SPDiffableSideBarHeader> { (cell, indexPath, item) in
57+
var content = UIListContentConfiguration.sidebarHeader()
58+
content.text = item.text
59+
content.image = nil
60+
cell.contentConfiguration = content
61+
cell.accessories = item.accessories
62+
}
63+
return collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: item)
64+
}
65+
return cellProvider
66+
}
67+
}

0 commit comments

Comments
 (0)