Skip to content

Commit 74d3490

Browse files
authored
Merge pull request #4 from smajdalf/diffable-collection-view
Diffable Collection View Provider and compositional Layout sample
2 parents e9b1440 + bda0bcd commit 74d3490

12 files changed

+580
-85
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.0.5] 30.10.2020
2+
### Added
3+
- Diffable CollectionView provider
4+
15
## [0.0.4] 07.10.2020
26
### Added
37
- add `TableView`, `SectionIndex`, `Section` to `configureSectionHeader` and `configureSectionFooterHeight`
@@ -9,7 +13,7 @@
913
## [0.0.2] 31.05.2020
1014

1115
### Changed
12-
- Rename DPProvider to GRProvider
16+
- rename DPProvider to GRProvider
1317

1418
## [0.0.1] 20.05.2020
1519

GRProvider.xcodeproj/project.pbxproj

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
/* End PBXAggregateTarget section */
2222

2323
/* Begin PBXBuildFile section */
24+
AE56A5A0254B011A009F98CB /* DiffableSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE56A59F254B011A009F98CB /* DiffableSection.swift */; };
25+
AE9CC26C254AF375009CDAE9 /* GRDiffableCollectionViewProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE9CC26B254AF375009CDAE9 /* GRDiffableCollectionViewProvider.swift */; };
26+
AE9CC275254AF4C9009CDAE9 /* DiffableCollectionProviderViewSampleController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE9CC274254AF4C9009CDAE9 /* DiffableCollectionProviderViewSampleController.swift */; };
2427
B18C775F2483F8D800B7E12F /* DeppDiffCollectionProviderSampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B18C774D2483F8D700B7E12F /* DeppDiffCollectionProviderSampleViewController.swift */; };
2528
B18C77602483F8D800B7E12F /* CollectionProviderSampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B18C774E2483F8D700B7E12F /* CollectionProviderSampleViewController.swift */; };
2629
B18C77612483F8D800B7E12F /* SimpleCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B18C774F2483F8D700B7E12F /* SimpleCollectionViewCell.swift */; };
@@ -106,6 +109,9 @@
106109
/* End PBXContainerItemProxy section */
107110

108111
/* Begin PBXFileReference section */
112+
AE56A59F254B011A009F98CB /* DiffableSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiffableSection.swift; sourceTree = "<group>"; };
113+
AE9CC26B254AF375009CDAE9 /* GRDiffableCollectionViewProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GRDiffableCollectionViewProvider.swift; sourceTree = "<group>"; };
114+
AE9CC274254AF4C9009CDAE9 /* DiffableCollectionProviderViewSampleController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiffableCollectionProviderViewSampleController.swift; sourceTree = "<group>"; };
109115
B18C770C2483F80400B7E12F /* Sample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sample.app; sourceTree = BUILT_PRODUCTS_DIR; };
110116
B18C774D2483F8D700B7E12F /* DeppDiffCollectionProviderSampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeppDiffCollectionProviderSampleViewController.swift; sourceTree = "<group>"; };
111117
B18C774E2483F8D700B7E12F /* CollectionProviderSampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionProviderSampleViewController.swift; sourceTree = "<group>"; };
@@ -125,9 +131,9 @@
125131
B18C776F2483F8FD00B7E12F /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
126132
B18C77742483F94B00B7E12F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
127133
B18C777F2483FCCB00B7E12F /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
128-
"DeepDiff::DeepDiff::Product" /* DeepDiff.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = DeepDiff.framework; sourceTree = BUILT_PRODUCTS_DIR; };
134+
"DeepDiff::DeepDiff::Product" /* DeepDiff.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DeepDiff.framework; sourceTree = BUILT_PRODUCTS_DIR; };
129135
"GRProvider::GRProvider::Product" /* GRProvider.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = GRProvider.framework; sourceTree = BUILT_PRODUCTS_DIR; };
130-
"GRProvider::GRProviderTests::Product" /* GRProviderTests.xctest */ = {isa = PBXFileReference; lastKnownFileType = file; path = GRProviderTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
136+
"GRProvider::GRProviderTests::Product" /* GRProviderTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; path = GRProviderTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
131137
OBJ_10 /* CollectionViewExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionViewExtensions.swift; sourceTree = "<group>"; };
132138
OBJ_11 /* GRCollectionViewProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GRCollectionViewProvider.swift; sourceTree = "<group>"; };
133139
OBJ_12 /* GRDeepDiffCollectionViewProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GRDeepDiffCollectionViewProvider.swift; sourceTree = "<group>"; };
@@ -215,6 +221,24 @@
215221
/* End PBXFrameworksBuildPhase section */
216222

217223
/* Begin PBXGroup section */
224+
AE56A5E7254BFCDE009F98CB /* Deep Diff */ = {
225+
isa = PBXGroup;
226+
children = (
227+
OBJ_12 /* GRDeepDiffCollectionViewProvider.swift */,
228+
OBJ_13 /* DeepDiffCollectionViewBindingExtension.swift */,
229+
OBJ_14 /* DeepDiffCollectionViewUpdateExtensions.swift */,
230+
);
231+
path = "Deep Diff";
232+
sourceTree = "<group>";
233+
};
234+
AE56A5E8254BFCF9009F98CB /* Diffable */ = {
235+
isa = PBXGroup;
236+
children = (
237+
AE9CC26B254AF375009CDAE9 /* GRDiffableCollectionViewProvider.swift */,
238+
);
239+
path = Diffable;
240+
sourceTree = "<group>";
241+
};
218242
B18C770D2483F80400B7E12F /* Sample */ = {
219243
isa = PBXGroup;
220244
children = (
@@ -245,6 +269,7 @@
245269
B18C774E2483F8D700B7E12F /* CollectionProviderSampleViewController.swift */,
246270
B18C774F2483F8D700B7E12F /* SimpleCollectionViewCell.swift */,
247271
B18C77502483F8D700B7E12F /* SimpleCollectionViewSupplementaryView.swift */,
272+
AE9CC274254AF4C9009CDAE9 /* DiffableCollectionProviderViewSampleController.swift */,
248273
);
249274
path = "Collection View";
250275
sourceTree = "<group>";
@@ -267,17 +292,18 @@
267292
B18C77592483F8D700B7E12F /* UITableViewExtensions.swift */,
268293
B18C775A2483F8D700B7E12F /* UICollectionViewExtensions.swift */,
269294
B18C775B2483F8D700B7E12F /* UIKitExtensions.swift */,
295+
AE56A59F254B011A009F98CB /* DiffableSection.swift */,
270296
);
271297
path = Common;
272298
sourceTree = "<group>";
273299
};
274300
OBJ_19 /* Table View */ = {
275301
isa = PBXGroup;
276302
children = (
277-
OBJ_20 /* GRSimpleTableViewProvider.swift */,
278-
OBJ_21 /* GRTableViewProvider.swift */,
279303
OBJ_22 /* Deep Diff */,
280304
OBJ_26 /* Diffable */,
305+
OBJ_20 /* GRSimpleTableViewProvider.swift */,
306+
OBJ_21 /* GRTableViewProvider.swift */,
281307
OBJ_29 /* TableViewExtensions.swift */,
282308
OBJ_30 /* TableViewProvider.swift */,
283309
);
@@ -423,11 +449,10 @@
423449
OBJ_9 /* Collection View */ = {
424450
isa = PBXGroup;
425451
children = (
452+
AE56A5E7254BFCDE009F98CB /* Deep Diff */,
453+
AE56A5E8254BFCF9009F98CB /* Diffable */,
426454
OBJ_10 /* CollectionViewExtensions.swift */,
427455
OBJ_11 /* GRCollectionViewProvider.swift */,
428-
OBJ_12 /* GRDeepDiffCollectionViewProvider.swift */,
429-
OBJ_13 /* DeepDiffCollectionViewBindingExtension.swift */,
430-
OBJ_14 /* DeepDiffCollectionViewUpdateExtensions.swift */,
431456
);
432457
path = "Collection View";
433458
sourceTree = "<group>";
@@ -595,6 +620,7 @@
595620
files = (
596621
B18C77672483F8D800B7E12F /* TableViewSampleController.swift in Sources */,
597622
B18C77662483F8D800B7E12F /* DiffableTableViewSampleController.swift in Sources */,
623+
AE56A5A0254B011A009F98CB /* DiffableSection.swift in Sources */,
598624
B18C77692483F8D800B7E12F /* UITableViewExtensions.swift in Sources */,
599625
B18C77612483F8D800B7E12F /* SimpleCollectionViewCell.swift in Sources */,
600626
B18C77702483F8FD00B7E12F /* AppDelegate.swift in Sources */,
@@ -604,6 +630,7 @@
604630
B18C776B2483F8D800B7E12F /* UIKitExtensions.swift in Sources */,
605631
B18C77642483F8D800B7E12F /* SimpleTableViewCell.swift in Sources */,
606632
B18C77652483F8D800B7E12F /* SimpleTableViewSampleController.swift in Sources */,
633+
AE9CC275254AF4C9009CDAE9 /* DiffableCollectionProviderViewSampleController.swift in Sources */,
607634
B18C77602483F8D800B7E12F /* CollectionProviderSampleViewController.swift in Sources */,
608635
B18C77622483F8D800B7E12F /* SimpleCollectionViewSupplementaryView.swift in Sources */,
609636
);
@@ -658,6 +685,7 @@
658685
OBJ_91 /* GRCollectionViewProvider.swift in Sources */,
659686
OBJ_92 /* GRDeepDiffCollectionViewProvider.swift in Sources */,
660687
OBJ_93 /* DeepDiffCollectionViewBindingExtension.swift in Sources */,
688+
AE9CC26C254AF375009CDAE9 /* GRDiffableCollectionViewProvider.swift in Sources */,
661689
OBJ_94 /* DeepDiffCollectionViewUpdateExtensions.swift in Sources */,
662690
OBJ_95 /* DeepDiffHelper.swift in Sources */,
663691
OBJ_96 /* Displayable.swift in Sources */,
@@ -865,7 +893,6 @@
865893
INFOPLIST_FILE = GRProvider.xcodeproj/GRProviderTests_Info.plist;
866894
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
867895
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/../Frameworks @loader_path/Frameworks";
868-
MACOSX_DEPLOYMENT_TARGET = 10.10;
869896
OTHER_CFLAGS = "$(inherited)";
870897
OTHER_LDFLAGS = "$(inherited)";
871898
OTHER_SWIFT_FLAGS = "$(inherited)";
@@ -890,7 +917,6 @@
890917
INFOPLIST_FILE = GRProvider.xcodeproj/GRProviderTests_Info.plist;
891918
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
892919
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/../Frameworks @loader_path/Frameworks";
893-
MACOSX_DEPLOYMENT_TARGET = 10.10;
894920
OTHER_CFLAGS = "$(inherited)";
895921
OTHER_LDFLAGS = "$(inherited)";
896922
OTHER_SWIFT_FLAGS = "$(inherited)";
@@ -917,7 +943,7 @@
917943
"SWIFT_PACKAGE=1",
918944
"DEBUG=1",
919945
);
920-
MACOSX_DEPLOYMENT_TARGET = 10.10;
946+
MACOSX_DEPLOYMENT_TARGET = 10.11;
921947
ONLY_ACTIVE_ARCH = YES;
922948
OTHER_SWIFT_FLAGS = "$(inherited) -DXcode";
923949
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -942,7 +968,7 @@
942968
"$(inherited)",
943969
"SWIFT_PACKAGE=1",
944970
);
945-
MACOSX_DEPLOYMENT_TARGET = 10.10;
971+
MACOSX_DEPLOYMENT_TARGET = 10.11;
946972
OTHER_SWIFT_FLAGS = "$(inherited) -DXcode";
947973
PRODUCT_NAME = "$(TARGET_NAME)";
948974
SDKROOT = macosx;
@@ -965,7 +991,6 @@
965991
INFOPLIST_FILE = GRProvider.xcodeproj/DeepDiff_Info.plist;
966992
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
967993
LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
968-
MACOSX_DEPLOYMENT_TARGET = 10.11;
969994
OTHER_CFLAGS = "$(inherited)";
970995
OTHER_LDFLAGS = "$(inherited)";
971996
OTHER_SWIFT_FLAGS = "$(inherited)";
@@ -993,7 +1018,6 @@
9931018
INFOPLIST_FILE = GRProvider.xcodeproj/DeepDiff_Info.plist;
9941019
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
9951020
LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
996-
MACOSX_DEPLOYMENT_TARGET = 10.11;
9971021
OTHER_CFLAGS = "$(inherited)";
9981022
OTHER_LDFLAGS = "$(inherited)";
9991023
OTHER_SWIFT_FLAGS = "$(inherited)";
@@ -1039,7 +1063,6 @@
10391063
INFOPLIST_FILE = GRProvider.xcodeproj/GRProvider_Info.plist;
10401064
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
10411065
LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
1042-
MACOSX_DEPLOYMENT_TARGET = 10.10;
10431066
MARKETING_VERSION = 0.0.1;
10441067
OTHER_CFLAGS = "$(inherited)";
10451068
OTHER_LDFLAGS = "$(inherited)";
@@ -1068,7 +1091,6 @@
10681091
INFOPLIST_FILE = GRProvider.xcodeproj/GRProvider_Info.plist;
10691092
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
10701093
LD_RUNPATH_SEARCH_PATHS = "$(inherited) $(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
1071-
MACOSX_DEPLOYMENT_TARGET = 10.10;
10721094
MARKETING_VERSION = 0.0.1;
10731095
OTHER_CFLAGS = "$(inherited)";
10741096
OTHER_LDFLAGS = "$(inherited)";

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ You can use this type of GRProviders:
7575
3. `GRDiffableTableViewProvider` -> Inherits all functionality of `GRTableViewProvider` but uses `UITableViewDiffableDataSource` API for diffing and animating
7676
4. `GRDeepDiffTableViewProvider` -> Inherits all functionality of `GRTableViewProvider` but uses `DeepDiff` framework for diffing and animating. More info about framework [click here](https://github.com/onmyway133/DeepDiff).
7777
5. `GRCollectionViewProvider` -> Default provider for the CollectionView
78+
6. `GRDeepDiffCollectionViewProvider` -> Inherits all functionality of `GRCollectionViewProvider` but uses `DeepDiff` framework for diffing and animating. More info about framework [click here](https://github.com/onmyway133/DeepDiff).
79+
7. `GRDiffableCollectionViewProvider` -> CollectionView provider that uses `UICollectionViewDiffableDataSource` as a data source and leaves the layout handling for `collectionViewLayout`. It is recommended to use this provider alongside `UICollectionViewCompositionalLayout` or any custom layout.
7880

7981
#### Define model
8082
Firstly you need to model your data, showed in the `UITableView` or `UICollectionView` using any type you choose.
@@ -309,10 +311,11 @@ Closure is fired, when the table view contains the refresh control. When `scroll
309311

310312
### UICollectionView Providers
311313

312-
Right know, we have only one 2 types of CollectionView Providers
314+
You can choose one of these types of providers:
313315

314316
1. `GRCollectionViewProvider` -> Default provider for the `UICollectionView`
315317
2. `GRDeepDiffCollectionViewProvider` -> Inherits all functionality of the `GRCollectionViewProvider` but uses the `DeepDiff` framework for diffing and animating. More info about the framework, [click here](https://github.com/onmyway133/DeepDiff)
318+
3. `GRDiffableCollectionViewProvider` -> CollectionView provider that uses `UICollectionViewDiffableDataSource` as a data source and leaves the layout handling for `collectionViewLayout`. It is recommended to use this provider alongside `UICollectionViewCompositionalLayout` or any custom layout. Therefore some of the features as `cellSize`, `sectionInsets` and others are not available in this provider, selected `collectionViewLayout` should handle all the layout itself.
316319

317320
**Features:**
318321

@@ -328,7 +331,7 @@ Right know, we have only one 2 types of CollectionView Providers
328331
10. `configureWillEndDragging: WillEndDraggingProvider` & `configureDidEndDragging: DidEndDraggingProvider`
329332
11. `cellSize: CGSize`
330333
12. `sectionInsets: UIEdgeInsets`
331-
13. `minimumLineSpacingForSection: CGFloat`
334+
13. `minimumLineSpacingForSection: CGFloat`
332335
14. `minInteritemSpacingForSection: CGFloat`
333336

334337

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// DiffableSection.swift
3+
// Sample
4+
//
5+
// Created by Marek Spalek on 29/10/2020.
6+
//
7+
8+
import GRProvider
9+
10+
struct DiffableStepConfigurator {
11+
let sections: [DiffableSection]
12+
}
13+
14+
struct DiffableSection: Sectionable, Hashable {
15+
16+
struct Item: Hashable {
17+
18+
let title: String
19+
20+
init(title: String) {
21+
self.title = title
22+
}
23+
24+
}
25+
26+
var items: [Item]
27+
var title: String?
28+
29+
init(items: [Item], title: String?) {
30+
self.items = items
31+
self.title = title
32+
}
33+
34+
static func ==(lhs: DiffableSection, rhs: DiffableSection) -> Bool {
35+
lhs.title == rhs.title
36+
}
37+
38+
func hash(into hasher: inout Hasher) {
39+
hasher.combine(title)
40+
}
41+
42+
}

0 commit comments

Comments
 (0)