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

Commit

Permalink
Merge pull request #139 from apptekstudios/v1.6candidate
Browse files Browse the repository at this point in the history
V1.6
  • Loading branch information
apptekstudios authored Apr 30, 2020
2 parents 1c39ef6 + d8dee4c commit 88a0ecf
Show file tree
Hide file tree
Showing 61 changed files with 3,448 additions and 2,411 deletions.
4 changes: 2 additions & 2 deletions ASCollectionView-SwiftUI.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

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

s.description = <<-DESC
Expand All @@ -22,5 +22,5 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '11.0'
s.swift_versions = '5.2'
s.source_files = 'Sources/ASCollectionView/**/*'

s.dependency 'DifferenceKit', '~> 1.1'
end
12 changes: 12 additions & 0 deletions Demo/ASCollectionViewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
B8A95E3E236081500017A7EA /* MagazineLayoutScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8A95E3D236081500017A7EA /* MagazineLayoutScreen.swift */; };
B8C00A972376350B0066348C /* AdjustableGridScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8C00A96237634E90066348C /* AdjustableGridScreen.swift */; };
B8D8292E2371077800D3F0AE /* SampleUsage.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8D8292D2371077400D3F0AE /* SampleUsage.swift */; };
B8FCC331244191F0003173CA /* TableViewDragAndDropScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8FCC330244191F0003173CA /* TableViewDragAndDropScreen.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -75,6 +76,7 @@
B8A95E3D236081500017A7EA /* MagazineLayoutScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MagazineLayoutScreen.swift; sourceTree = "<group>"; };
B8C00A96237634E90066348C /* AdjustableGridScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdjustableGridScreen.swift; sourceTree = "<group>"; };
B8D8292D2371077400D3F0AE /* SampleUsage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SampleUsage.swift; path = ../readmeAssets/SampleUsage.swift; sourceTree = "<group>"; };
B8FCC330244191F0003173CA /* TableViewDragAndDropScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewDragAndDropScreen.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -175,6 +177,7 @@
B86C6F38234B0B9D00522AEF /* Screens */ = {
isa = PBXGroup;
children = (
B8FCC32F244191DD003173CA /* TableViewDragAndDrop */,
B8268B502363EEF0008C99A3 /* Reminders */,
B8A95E3723607F760017A7EA /* MagazineLayout */,
B89129FB235DB6ED00D8BA90 /* Tags */,
Expand Down Expand Up @@ -249,6 +252,14 @@
path = AdjustableLayout;
sourceTree = "<group>";
};
B8FCC32F244191DD003173CA /* TableViewDragAndDrop */ = {
isa = PBXGroup;
children = (
B8FCC330244191F0003173CA /* TableViewDragAndDropScreen.swift */,
);
path = TableViewDragAndDrop;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -361,6 +372,7 @@
B86C6F4A234B0B9D00522AEF /* AppStoreScreen.swift in Sources */,
B8268B582363EF37008C99A3 /* GroupModel.swift in Sources */,
B86C6F48234B0B9D00522AEF /* App.swift in Sources */,
B8FCC331244191F0003173CA /* TableViewDragAndDropScreen.swift in Sources */,
B8268B522363EF03008C99A3 /* RemindersScreen.swift in Sources */,
B86C6F47234B0B9D00522AEF /* Post.swift in Sources */,
B899D70123752CEC001BB5FA /* WaterfallScreen.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"object": {
"pins": [
{
"package": "DifferenceKit",
"repositoryURL": "https://github.com/ra1028/DifferenceKit",
"state": {
"branch": null,
"revision": "14c66681e12a38b81045f44c6c29724a0d4b0e72",
"version": "1.1.5"
}
},
{
"package": "MagazineLayout",
"repositoryURL": "https://github.com/airbnb/MagazineLayout",
Expand Down
5 changes: 5 additions & 0 deletions Demo/ASCollectionViewDemo/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ struct MainView: View
Image(systemName: "8.square.fill")
Text("Adjustable layout")
}
NavigationLink(destination: TableViewDragAndDropScreen())
{
Image(systemName: "9.square.fill")
Text("Multiple TableView drag&drop")
}
}
Section(header: Text("Modified examples"))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct AdjustableGridScreen: View
ASCollectionView(
section: section)
.layout(self.layout)
.shouldInvalidateLayoutOnStateChange(true)
.navigationBarTitle("Adjustable Layout", displayMode: .inline)
}
.navigationBarItems(
Expand Down
15 changes: 8 additions & 7 deletions Demo/ASCollectionViewDemo/Screens/AppStore/AppStoreScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ struct AppStoreScreen: View
{
ASCollectionView(sections: self.sections)
.layout(self.layout)
.edgesIgnoringSafeArea(.all)
.shouldAttemptToMaintainScrollPositionOnOrientationChange(maintainPosition: false)
.navigationBarTitle("Apps", displayMode: .large)
.edgesIgnoringSafeArea(.all)
}

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

let itemsGroup = NSCollectionLayoutGroup.horizontal(
let itemsGroup = NSCollectionLayoutGroup.vertical(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(0.9 / columnsToFit),
widthDimension: .fractionalWidth(0.8 / columnsToFit),
heightDimension: .absolute(280)),
subitems: [item])
itemsGroup.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 8, bottom: 10, trailing: 8)
subitem: item, count: 1)

let section = NSCollectionLayoutSection(group: itemsGroup)
section.interGroupSpacing = 20
section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 20, bottom: 0, trailing: 20)
section.orthogonalScrollingBehavior = .groupPaging
return section
Expand Down Expand Up @@ -164,7 +165,7 @@ extension AppStoreScreen
let header = NSCollectionLayoutBoundarySupplementaryItem(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .estimated(34)),
heightDimension: .absolute(34)),
elementKind: UICollectionView.elementKindSectionHeader,
alignment: .top)
header.contentInsets.leading = nestedGroup.contentInsets.leading
Expand Down Expand Up @@ -201,7 +202,7 @@ extension AppStoreScreen
let header = NSCollectionLayoutBoundarySupplementaryItem(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .estimated(34)),
heightDimension: .absolute(34)),
elementKind: UICollectionView.elementKindSectionHeader,
alignment: .top)
header.contentInsets.leading = nestedGroup.contentInsets.leading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct InstaFeedScreen: View
{ item, _ in
PostView(post: item)
}
.tableViewSetEstimatedSizes(rowHeight: 500, headerHeight: 50) // Optional: Provide reasonable estimated heights for this section
.tableViewSetEstimatedSizes(headerHeight: 50) // Optional: Provide reasonable estimated heights for this section
.sectionHeader
{
VStack(spacing: 0)
Expand Down
2 changes: 1 addition & 1 deletion Demo/ASCollectionViewDemo/Screens/InstaFeed/PostView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct PostView: View
.onTapGesture
{
self.captionExpanded.toggle()
self.invalidateCellLayout()
self.invalidateCellLayout?(false)
}
Text("View all \(post.comments) comments").foregroundColor(Color(.systemGray))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ struct MagazineLayoutScreen: View
{
data.enumerated().map
{ (offset, sectionData) -> ASCollectionViewSection<Int> in
ASCollectionViewSection(id: offset, data: sectionData, onCellEvent: onCellEvent, contextMenuProvider: contextMenuProvider)
ASCollectionViewSection(
id: offset,
data: sectionData,
onCellEvent: onCellEvent,
contextMenuProvider: contextMenuProvider)
{ item, _ in
ASRemoteImageView(item.url)
.aspectRatio(1, contentMode: .fit)
Expand Down Expand Up @@ -64,7 +68,7 @@ struct MagazineLayoutScreen: View
}
}

func contextMenuProvider(_ post: Post) -> UIContextMenuConfiguration?
func contextMenuProvider(index: Int, post: Post) -> UIContextMenuConfiguration?
{
let configuration = UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { (_) -> UIMenu? in
let testAction = UIAction(title: "Test") { _ in
Expand Down
29 changes: 25 additions & 4 deletions Demo/ASCollectionViewDemo/Screens/PhotoGrid/PhotoGridScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ struct PhotoGridScreen: View
data: data,
selectedItems: $selectedItems,
onCellEvent: onCellEvent,
itemProvider: { item in
// Example of returning a custom item provider (eg. to support drag-drop to other apps)
NSItemProvider(object: item.url as NSURL)
})
dragDropConfig: dragDropConfig,
contextMenuProvider: contextMenuProvider)
{ item, state in
ZStack(alignment: .bottomTrailing)
{
Expand Down Expand Up @@ -114,6 +112,20 @@ struct PhotoGridScreen: View
}
}

func contextMenuProvider(int: Int, post: Post) -> UIContextMenuConfiguration?
{
let configuration = UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { (_) -> UIMenu? in
let testAction = UIAction(title: "Do nothing") { _ in
//
}
let testAction2 = UIAction(title: "Try dragging the photo") { _ in
//
}
return UIMenu(title: "", image: nil, identifier: nil, options: [], children: [testAction, testAction2])
}
return configuration
}

func destinationForItem(_ item: Post) -> some View
{
ScrollView {
Expand Down Expand Up @@ -167,6 +179,15 @@ extension PhotoGridScreen
}
}
}

var dragDropConfig: ASDragDropConfig<Post>
{
ASDragDropConfig<Post>(dataBinding: $data)
.enableReordering(shouldMoveItem: nil)
.dragItemProvider { item in
NSItemProvider(object: item.url as NSURL)
}
}
}

struct GridView_Previews: PreviewProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// ASCollectionView. Created by Apptek Studios 2019

import ASCollectionView
import SwiftUI

struct TableViewDragAndDropScreen: View
{
@State var groupA: [String] = (0 ... 4).map { "Item A-\($0)" }
@State var groupB: [String] = (0 ... 4).map { "Item B-\($0)" }
@State var groupC: [String] = (0 ... 4).map { "Item C-\($0)" }
@State var groupD: [String] = (0 ... 4).map { "Item D-\($0)" }

var body: some View
{
VStack {
Text("Drag within a tableview to move.\nDrag between tableviews to copy.")
.padding()
HStack {
ASTableView {
ASSection(
id: 0,
data: groupA,
dataID: \.self,
dragDropConfig: ASDragDropConfig(dataBinding: $groupA).enableReordering(),
onSwipeToDelete: { index, _, callback in
withAnimation {
self.groupA.remove(at: index)
callback(true)
}
})
{ item, _ in
Text(item)
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
}
.sectionHeader {
header("Section A")
}
ASSection(
id: 1,
data: groupB,
dataID: \.self,
dragDropConfig: ASDragDropConfig(dataBinding: $groupB).enableReordering(),
onSwipeToDelete: { index, _, callback in
withAnimation {
self.groupB.remove(at: index)
callback(true)
}
}) { item, _ in
Text(item)
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
}
.sectionHeader {
header("Section B")
}
}
Color.blue.frame(width: 10)
ASTableView {
ASSection(
id: 0,
data: groupC,
dataID: \.self,
dragDropConfig: ASDragDropConfig(dataBinding: $groupC).enableReordering(),
onSwipeToDelete: { index, _, callback in
withAnimation {
self.groupC.remove(at: index)
callback(true)
}
}) { item, _ in
Text(item)
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
}
.sectionHeader {
header("Section C")
}
ASSection(
id: 1,
data: groupD,
dataID: \.self,
dragDropConfig: ASDragDropConfig(dataBinding: $groupD).enableReordering(),
onSwipeToDelete: { index, _, callback in
withAnimation {
self.groupD.remove(at: index)
callback(true)
}
}) { item, _ in
Text(item)
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
}
.sectionHeader {
header("Section D")
}
}
}
}
.navigationBarTitle("Drag & drop", displayMode: .inline)
}

func header(_ string: String) -> some View
{
Text(string)
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.background(Color(.secondarySystemBackground))
}
}

struct TableViewDragAndDropScreen_Previews: PreviewProvider
{
static var previews: some View
{
TableViewDragAndDropScreen()
}
}
4 changes: 2 additions & 2 deletions Demo/BuildTools/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/nicklockwood/SwiftFormat",
"state": {
"branch": null,
"revision": "2f1d164cb58c9a2da0452db846b7333d49f556af",
"version": "0.44.6"
"revision": "03989b9a28f98ea5cad5ca2b22024a8b67aca31c",
"version": "0.44.7"
}
}
]
Expand Down
16 changes: 16 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"object": {
"pins": [
{
"package": "DifferenceKit",
"repositoryURL": "https://github.com/ra1028/DifferenceKit",
"state": {
"branch": null,
"revision": "14c66681e12a38b81045f44c6c29724a0d4b0e72",
"version": "1.1.5"
}
}
]
},
"version": 1
}
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ let package = Package(name: "ASCollectionView",
platforms: [.iOS(.v11)],
products: [// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(name: "ASCollectionView",
targets: ["ASCollectionView"])
targets: ["ASCollectionView"]),
.library(name: "ASCollectionViewDynamic", type: .dynamic, targets: ["ASCollectionView"]),
],
dependencies: [
.package(url: "https://github.com/ra1028/DifferenceKit", .upToNextMajor(from: Version(1, 1, 5)))
],
targets: [
.target(name: "ASCollectionView",
dependencies: []),
dependencies: ["DifferenceKit"]),
]
)
Loading

0 comments on commit 88a0ecf

Please sign in to comment.