Skip to content
This repository was archived by the owner on Nov 4, 2022. It is now read-only.

Commit 88a0ecf

Browse files
Merge pull request #139 from apptekstudios/v1.6candidate
V1.6
2 parents 1c39ef6 + d8dee4c commit 88a0ecf

File tree

61 files changed

+3448
-2411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3448
-2411
lines changed

ASCollectionView-SwiftUI.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Pod::Spec.new do |s|
33
s.name = 'ASCollectionView-SwiftUI'
4-
s.version = '1.5.0'
4+
s.version = '1.6.0'
55
s.summary = 'A SwiftUI collection view with support for custom layouts, preloading, and more. '
66

77
s.description = <<-DESC
@@ -22,5 +22,5 @@ Pod::Spec.new do |s|
2222
s.ios.deployment_target = '11.0'
2323
s.swift_versions = '5.2'
2424
s.source_files = 'Sources/ASCollectionView/**/*'
25-
25+
s.dependency 'DifferenceKit', '~> 1.1'
2626
end

Demo/ASCollectionViewDemo.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
B8A95E3E236081500017A7EA /* MagazineLayoutScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8A95E3D236081500017A7EA /* MagazineLayoutScreen.swift */; };
4040
B8C00A972376350B0066348C /* AdjustableGridScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8C00A96237634E90066348C /* AdjustableGridScreen.swift */; };
4141
B8D8292E2371077800D3F0AE /* SampleUsage.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8D8292D2371077400D3F0AE /* SampleUsage.swift */; };
42+
B8FCC331244191F0003173CA /* TableViewDragAndDropScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8FCC330244191F0003173CA /* TableViewDragAndDropScreen.swift */; };
4243
/* End PBXBuildFile section */
4344

4445
/* Begin PBXFileReference section */
@@ -75,6 +76,7 @@
7576
B8A95E3D236081500017A7EA /* MagazineLayoutScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MagazineLayoutScreen.swift; sourceTree = "<group>"; };
7677
B8C00A96237634E90066348C /* AdjustableGridScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdjustableGridScreen.swift; sourceTree = "<group>"; };
7778
B8D8292D2371077400D3F0AE /* SampleUsage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SampleUsage.swift; path = ../readmeAssets/SampleUsage.swift; sourceTree = "<group>"; };
79+
B8FCC330244191F0003173CA /* TableViewDragAndDropScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewDragAndDropScreen.swift; sourceTree = "<group>"; };
7880
/* End PBXFileReference section */
7981

8082
/* Begin PBXFrameworksBuildPhase section */
@@ -175,6 +177,7 @@
175177
B86C6F38234B0B9D00522AEF /* Screens */ = {
176178
isa = PBXGroup;
177179
children = (
180+
B8FCC32F244191DD003173CA /* TableViewDragAndDrop */,
178181
B8268B502363EEF0008C99A3 /* Reminders */,
179182
B8A95E3723607F760017A7EA /* MagazineLayout */,
180183
B89129FB235DB6ED00D8BA90 /* Tags */,
@@ -249,6 +252,14 @@
249252
path = AdjustableLayout;
250253
sourceTree = "<group>";
251254
};
255+
B8FCC32F244191DD003173CA /* TableViewDragAndDrop */ = {
256+
isa = PBXGroup;
257+
children = (
258+
B8FCC330244191F0003173CA /* TableViewDragAndDropScreen.swift */,
259+
);
260+
path = TableViewDragAndDrop;
261+
sourceTree = "<group>";
262+
};
252263
/* End PBXGroup section */
253264

254265
/* Begin PBXNativeTarget section */
@@ -361,6 +372,7 @@
361372
B86C6F4A234B0B9D00522AEF /* AppStoreScreen.swift in Sources */,
362373
B8268B582363EF37008C99A3 /* GroupModel.swift in Sources */,
363374
B86C6F48234B0B9D00522AEF /* App.swift in Sources */,
375+
B8FCC331244191F0003173CA /* TableViewDragAndDropScreen.swift in Sources */,
364376
B8268B522363EF03008C99A3 /* RemindersScreen.swift in Sources */,
365377
B86C6F47234B0B9D00522AEF /* Post.swift in Sources */,
366378
B899D70123752CEC001BB5FA /* WaterfallScreen.swift in Sources */,

Demo/ASCollectionViewDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/ASCollectionViewDemo/MainView.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ struct MainView: View
5252
Image(systemName: "8.square.fill")
5353
Text("Adjustable layout")
5454
}
55+
NavigationLink(destination: TableViewDragAndDropScreen())
56+
{
57+
Image(systemName: "9.square.fill")
58+
Text("Multiple TableView drag&drop")
59+
}
5560
}
5661
Section(header: Text("Modified examples"))
5762
{

Demo/ASCollectionViewDemo/Screens/AdjustableLayout/AdjustableGridScreen.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct AdjustableGridScreen: View
8080
ASCollectionView(
8181
section: section)
8282
.layout(self.layout)
83+
.shouldInvalidateLayoutOnStateChange(true)
8384
.navigationBarTitle("Adjustable Layout", displayMode: .inline)
8485
}
8586
.navigationBarItems(

Demo/ASCollectionViewDemo/Screens/AppStore/AppStoreScreen.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ struct AppStoreScreen: View
6161
{
6262
ASCollectionView(sections: self.sections)
6363
.layout(self.layout)
64-
.edgesIgnoringSafeArea(.all)
64+
.shouldAttemptToMaintainScrollPositionOnOrientationChange(maintainPosition: false)
6565
.navigationBarTitle("Apps", displayMode: .large)
66+
.edgesIgnoringSafeArea(.all)
6667
}
6768

6869
func onCellEvent(_ event: CellEvent<App>, sectionID: Int)
@@ -127,14 +128,14 @@ extension AppStoreScreen
127128
widthDimension: .fractionalWidth(1.0),
128129
heightDimension: .fractionalHeight(1.0)))
129130

130-
let itemsGroup = NSCollectionLayoutGroup.horizontal(
131+
let itemsGroup = NSCollectionLayoutGroup.vertical(
131132
layoutSize: NSCollectionLayoutSize(
132-
widthDimension: .fractionalWidth(0.9 / columnsToFit),
133+
widthDimension: .fractionalWidth(0.8 / columnsToFit),
133134
heightDimension: .absolute(280)),
134-
subitems: [item])
135-
itemsGroup.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 8, bottom: 10, trailing: 8)
135+
subitem: item, count: 1)
136136

137137
let section = NSCollectionLayoutSection(group: itemsGroup)
138+
section.interGroupSpacing = 20
138139
section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 20, bottom: 0, trailing: 20)
139140
section.orthogonalScrollingBehavior = .groupPaging
140141
return section
@@ -164,7 +165,7 @@ extension AppStoreScreen
164165
let header = NSCollectionLayoutBoundarySupplementaryItem(
165166
layoutSize: NSCollectionLayoutSize(
166167
widthDimension: .fractionalWidth(1.0),
167-
heightDimension: .estimated(34)),
168+
heightDimension: .absolute(34)),
168169
elementKind: UICollectionView.elementKindSectionHeader,
169170
alignment: .top)
170171
header.contentInsets.leading = nestedGroup.contentInsets.leading
@@ -201,7 +202,7 @@ extension AppStoreScreen
201202
let header = NSCollectionLayoutBoundarySupplementaryItem(
202203
layoutSize: NSCollectionLayoutSize(
203204
widthDimension: .fractionalWidth(1.0),
204-
heightDimension: .estimated(34)),
205+
heightDimension: .absolute(34)),
205206
elementKind: UICollectionView.elementKindSectionHeader,
206207
alignment: .top)
207208
header.contentInsets.leading = nestedGroup.contentInsets.leading

Demo/ASCollectionViewDemo/Screens/InstaFeed/InstaFeedScreen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct InstaFeedScreen: View
5151
{ item, _ in
5252
PostView(post: item)
5353
}
54-
.tableViewSetEstimatedSizes(rowHeight: 500, headerHeight: 50) // Optional: Provide reasonable estimated heights for this section
54+
.tableViewSetEstimatedSizes(headerHeight: 50) // Optional: Provide reasonable estimated heights for this section
5555
.sectionHeader
5656
{
5757
VStack(spacing: 0)

Demo/ASCollectionViewDemo/Screens/InstaFeed/PostView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct PostView: View
7676
.onTapGesture
7777
{
7878
self.captionExpanded.toggle()
79-
self.invalidateCellLayout()
79+
self.invalidateCellLayout?(false)
8080
}
8181
Text("View all \(post.comments) comments").foregroundColor(Color(.systemGray))
8282
}

Demo/ASCollectionViewDemo/Screens/MagazineLayout/MagazineLayoutScreen.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ struct MagazineLayoutScreen: View
1616
{
1717
data.enumerated().map
1818
{ (offset, sectionData) -> ASCollectionViewSection<Int> in
19-
ASCollectionViewSection(id: offset, data: sectionData, onCellEvent: onCellEvent, contextMenuProvider: contextMenuProvider)
19+
ASCollectionViewSection(
20+
id: offset,
21+
data: sectionData,
22+
onCellEvent: onCellEvent,
23+
contextMenuProvider: contextMenuProvider)
2024
{ item, _ in
2125
ASRemoteImageView(item.url)
2226
.aspectRatio(1, contentMode: .fit)
@@ -64,7 +68,7 @@ struct MagazineLayoutScreen: View
6468
}
6569
}
6670

67-
func contextMenuProvider(_ post: Post) -> UIContextMenuConfiguration?
71+
func contextMenuProvider(index: Int, post: Post) -> UIContextMenuConfiguration?
6872
{
6973
let configuration = UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { (_) -> UIMenu? in
7074
let testAction = UIAction(title: "Test") { _ in

Demo/ASCollectionViewDemo/Screens/PhotoGrid/PhotoGridScreen.swift

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ struct PhotoGridScreen: View
2626
data: data,
2727
selectedItems: $selectedItems,
2828
onCellEvent: onCellEvent,
29-
itemProvider: { item in
30-
// Example of returning a custom item provider (eg. to support drag-drop to other apps)
31-
NSItemProvider(object: item.url as NSURL)
32-
})
29+
dragDropConfig: dragDropConfig,
30+
contextMenuProvider: contextMenuProvider)
3331
{ item, state in
3432
ZStack(alignment: .bottomTrailing)
3533
{
@@ -114,6 +112,20 @@ struct PhotoGridScreen: View
114112
}
115113
}
116114

115+
func contextMenuProvider(int: Int, post: Post) -> UIContextMenuConfiguration?
116+
{
117+
let configuration = UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { (_) -> UIMenu? in
118+
let testAction = UIAction(title: "Do nothing") { _ in
119+
//
120+
}
121+
let testAction2 = UIAction(title: "Try dragging the photo") { _ in
122+
//
123+
}
124+
return UIMenu(title: "", image: nil, identifier: nil, options: [], children: [testAction, testAction2])
125+
}
126+
return configuration
127+
}
128+
117129
func destinationForItem(_ item: Post) -> some View
118130
{
119131
ScrollView {
@@ -167,6 +179,15 @@ extension PhotoGridScreen
167179
}
168180
}
169181
}
182+
183+
var dragDropConfig: ASDragDropConfig<Post>
184+
{
185+
ASDragDropConfig<Post>(dataBinding: $data)
186+
.enableReordering(shouldMoveItem: nil)
187+
.dragItemProvider { item in
188+
NSItemProvider(object: item.url as NSURL)
189+
}
190+
}
170191
}
171192

172193
struct GridView_Previews: PreviewProvider

0 commit comments

Comments
 (0)