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

V1.6 #139

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e11ffec
Added dynamic library
kkla320 Apr 5, 2020
bc4d5b3
Merge pull request #129 from kkla320/dynamicTarget
apptekstudios Apr 7, 2020
41334c7
Custom DataSource and Diffing. Improve performance on large collections.
Apr 7, 2020
d7c7bf9
Fix drag & drop on iOS 13.4
Apr 8, 2020
6573882
TableView drag & drop support
Apr 8, 2020
06b5ef0
Refactoring + fix edge case where SwiftUI attempts to follow safeAreas
Apr 8, 2020
a815fff
Add context menu support to ASTableView
Apr 8, 2020
9e6ffcc
Add `index` to CellContext
Apr 10, 2020
885d316
Add debug-build-only check for duplicate sectionIDs
Apr 10, 2020
6bb7523
Refactoring
Apr 10, 2020
7719ea6
Rewrite drag&drop
Apr 11, 2020
e230a9b
Further work on drag&drop
Apr 11, 2020
c5d4e47
Refine API
Apr 11, 2020
3512687
Update supplementary cell code
Apr 11, 2020
c32687f
Improve workaround for SwiftUI not correctly adding VC to parent
Apr 13, 2020
a74dca2
Minor refactoring
Apr 15, 2020
b995eb5
Fix debug message
Apr 15, 2020
4b3beab
Rearrange and refactor entire source. Publicly accessible initialiser…
Apr 17, 2020
df94ae7
Remove unneccessary print in ASWaterfallLayout
Apr 19, 2020
a6b94ba
Add supplementary caching to ASTableView
Apr 19, 2020
62a2953
Add animation to onDelete in TableView demo
Apr 20, 2020
8a98490
Further refactoring
Apr 20, 2020
013e819
Further improvements of lifecycle & animations
Apr 20, 2020
2d3a72d
Raise podspec version to 1.6.0
Apr 20, 2020
ffddb7d
Fix tableview cell size invalidation
Apr 20, 2020
c4b2c7d
Refine header caching
Apr 20, 2020
4fd08b2
Make functions in ASCollectionViewDelegate open (allow overrides from…
Apr 23, 2020
9d2ec31
SwiftFormat
Apr 23, 2020
234f8f5
Fix regression
Apr 26, 2020
766d024
Fix some edge cases
Apr 29, 2020
aa2d944
Update podfile
Apr 29, 2020
d8dee4c
Update README.md
apptekstudios Apr 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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