Skip to content
This repository was archived by the owner on Nov 4, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ struct InstaFeedScreen: View
.list(itemSize: .absolute(100), sectionInsets: NSDirectionalEdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
}
.frame(height: 100)
.scrollIndicatorsEnabled(false)
.onCollectionViewReachedBoundary
.collectionViewScrollIndicatorsEnabled(false)
.collectionViewOnReachedBoundary
{ boundary in
print("Reached the \(boundary) boundary")
}
Expand Down Expand Up @@ -78,13 +78,13 @@ struct InstaFeedScreen: View
{
ASTableView(sections: sections)
.tableViewSeparatorsEnabled(false)
.onTableViewPullToRefresh { endRefreshing in
.tableViewOnPullToRefresh { endRefreshing in
print("PULL TO REFRESH")
Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { _ in
endRefreshing()
}
}
.onTableViewReachedBottom
.tableViewOnReachedBottom
{
self.loadMoreContent() // REACHED BOTTOM, LOADING MORE CONTENT
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@ struct MagazineLayoutScreen: View
{
data.enumerated().map
{ (offset, sectionData) -> ASCollectionViewSection<Int> in
ASCollectionViewSection(id: offset, data: sectionData, onCellEvent: onCellEvent)
ASCollectionViewSection(id: offset, data: sectionData, onCellEvent: onCellEvent, contextMenuProvider: contextMenuProvider)
{ item, _ in
ASRemoteImageView(item.url)
.aspectRatio(1, contentMode: .fit)
.contextMenu
{
Text("Test item")
Text("Another item")
}
}
.sectionSupplementary(ofKind: MagazineLayout.SupplementaryViewKind.sectionHeader)
{
Expand All @@ -46,7 +41,7 @@ struct MagazineLayoutScreen: View
.customDelegate(ASCollectionViewMagazineLayoutDelegate.init)
.edgesIgnoringSafeArea(.all)
.navigationBarTitle("Magazine Layout (custom delegate)", displayMode: .inline)
.onCollectionViewReachedBoundary
.collectionViewOnReachedBoundary
{ boundary in
print("Reached the \(boundary) boundary")
}
Expand All @@ -72,6 +67,16 @@ struct MagazineLayoutScreen: View
}
}
}

func contextMenuProvider(_ post: Post) -> UIContextMenuConfiguration? {
let configuration = UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { (suggestedActions) -> UIMenu? in
let testAction = UIAction(title: "Test") { (action) in
//
}
return UIMenu(title: "", image: nil, identifier: nil, options: [], children: [testAction])
}
return configuration
}
}

struct MagazineLayoutScreen_Previews: PreviewProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct PhotoGridScreen: View
selectedItems: $selectedItems,
section: section)
.layout(self.layout)
.initialScrollPosition(startingAtBottom ? .bottom : nil)
.collectionViewInitialScrollPosition(startingAtBottom ? .bottom : nil)
.navigationBarTitle("Explore", displayMode: .inline)
.navigationBarItems(
trailing:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ struct RemindersScreen: View
}
}
.layout(self.layout)
.contentInsets(.init(top: 20, left: 0, bottom: 20, right: 0))
.alwaysBounceVertical()
.collectionViewContentInsets(.init(top: 20, left: 0, bottom: 20, right: 0))
.collectionViewAlwaysBounceVertical()
.background(Color(.systemGroupedBackground))
.edgesIgnoringSafeArea(.all)
.navigationBarTitle("Reminders", displayMode: .inline)
Expand Down
2 changes: 1 addition & 1 deletion Demo/ASCollectionViewDemo/Screens/Tags/TagStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TagStore: ObservableObject
items = TagStore.randomItems()
}

fileprivate static let allWords = ["alias", "consequatur", "aut", "perferendis", "sit", "voluptatem", "accusantium", "doloremque", "aperiam", "eaque", "ipsa", "quae", "ab", "illo", "inventore", "veritatis", "et", "quasi", "architecto", "beatae", "vitae", "dicta", "sunt", "explicabo", "aspernatur", "aut", "maiores", "doloribus", "asperiores", "repellat"]
fileprivate static let allWords = ["thisisaveryverylongtagthatshouldrequiremorethanonelinetofit", "alias", "consequatur", "aut", "perferendis", "sit", "voluptatem", "accusantium", "doloremque", "aperiam", "eaque", "ipsa", "quae", "ab", "illo", "inventore", "veritatis", "et", "quasi", "architecto", "beatae", "vitae", "dicta", "sunt", "explicabo", "aspernatur", "aut", "maiores", "doloribus", "asperiores", "repellat"]

static func randomItems() -> [Item]
{
Expand Down
15 changes: 8 additions & 7 deletions Demo/ASCollectionViewDemo/Screens/Tags/TagsScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ struct TagsScreen: View
HStack
{
Spacer()
Text("Tap screen to reload new tags")
Text("Tap this button to reload new tags")
.padding()
.background(Color(.secondarySystemBackground))
Spacer()
}
.onTapGesture
{
self.store.refreshStore()
}
Text("Tags:")
.font(.title)

Expand All @@ -32,7 +36,7 @@ struct TagsScreen: View
ASCollectionViewSection(id: 0, data: store.items)
{ item, _ in
Text(item.displayString)
.fixedSize()
.fixedSize(horizontal: false, vertical: true)
.padding(5)
.background(Color(.systemGray))
.cornerRadius(5)
Expand All @@ -44,7 +48,8 @@ struct TagsScreen: View
return fl
}
.shrinkToContentSize(isEnabled: shrinkToSize, $contentSize, dimensionToShrink: .vertical)

.collectionViewAllowCellWidthToExceedCollectionContentSize(false)

if shrinkToSize
{
Rectangle().fill(Color(.secondarySystemBackground))
Expand All @@ -56,10 +61,6 @@ struct TagsScreen: View
}
}
.padding()
.onTapGesture
{
self.store.refreshStore()
}
.navigationBarTitle("Tags", displayMode: .inline)
}
}
Expand Down
97 changes: 54 additions & 43 deletions Demo/ASCollectionViewDemo/Screens/Waterfall/WaterfallScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import UIKit
/// THIS IS A WORK IN PROGRESS
struct WaterfallScreen: View
{
@State var data: [Post] = DataSource.postsForWaterfallSection(1, number: 1000)
@State var data: [[Post]] = (0...10).map { DataSource.postsForWaterfallSection($0, number: 100) }
@State var selectedItems: [SectionID: IndexSet] = [:]
@State var columnMinSize: CGFloat = 150

Expand All @@ -19,50 +19,57 @@ struct WaterfallScreen: View

typealias SectionID = Int

var section: ASCollectionViewSection<SectionID>
var sections: [ASCollectionViewSection<SectionID>]
{
ASCollectionViewSection(
id: 0,
data: data,
onCellEvent: onCellEvent)
{ item, state in
GeometryReader
{ geom in
ZStack(alignment: .bottomTrailing)
{
ASRemoteImageView(item.url)
.scaledToFill()
.frame(width: geom.size.width, height: geom.size.height)
.opacity(state.isSelected ? 0.7 : 1.0)

if state.isSelected
{
ZStack
data.enumerated().map { (offset, sectionData) in
ASCollectionViewSection(
id: offset,
data: sectionData,
onCellEvent: onCellEvent)
{ item, state in
GeometryReader
{ geom in
ZStack(alignment: .bottomTrailing)
{
Circle()
.fill(Color.blue)
Circle()
.strokeBorder(Color.white, lineWidth: 2)
Image(systemName: "checkmark")
.font(.system(size: 10, weight: .bold))
.foregroundColor(.white)
ASRemoteImageView(item.url)
.scaledToFill()
.frame(width: geom.size.width, height: geom.size.height)
.opacity(state.isSelected ? 0.7 : 1.0)

if state.isSelected
{
ZStack
{
Circle()
.fill(Color.blue)
Circle()
.strokeBorder(Color.white, lineWidth: 2)
Image(systemName: "checkmark")
.font(.system(size: 10, weight: .bold))
.foregroundColor(.white)
}
.frame(width: 20, height: 20)
.padding(10)
}
else
{
Text("\(item.offset)")
.font(.title)
.bold()
.padding(2)
.background(Color(.systemBackground).opacity(0.5))
.cornerRadius(4)
.padding(10)
}
}
.frame(width: 20, height: 20)
.padding(10)
}
else
{
Text("\(item.offset)")
.font(.title)
.bold()
.padding(2)
.background(Color(.systemBackground).opacity(0.5))
.cornerRadius(4)
.padding(10)
}
.frame(width: geom.size.width, height: geom.size.height)
.clipped()
}
.frame(width: geom.size.width, height: geom.size.height)
.clipped()
}.sectionHeader {
Text("Section \(offset)")
.padding()
.frame(idealWidth: .infinity, maxWidth: .infinity, idealHeight: .infinity, maxHeight: .infinity, alignment: .leading)
.background(Color.blue)
}
}
}
Expand All @@ -82,10 +89,10 @@ struct WaterfallScreen: View

ASCollectionView(
selectedItems: $selectedItems,
sections: [section])
sections: sections)
.layout(self.layout)
.customDelegate(WaterfallScreenLayoutDelegate.init)
.contentInsets(.init(top: 0, left: 10, bottom: 10, right: 10))
.collectionViewContentInsets(.init(top: 0, left: 10, bottom: 10, right: 10))
.navigationBarTitle("Waterfall Layout", displayMode: .inline)
.navigationBarItems(
trailing:
Expand Down Expand Up @@ -160,6 +167,10 @@ struct WaterfallScreen_Previews: PreviewProvider

class WaterfallScreenLayoutDelegate: ASCollectionViewDelegate, ASWaterfallLayoutDelegate
{
func heightForHeader(sectionIndex: Int) -> CGFloat? {
60
}

/// We explicitely provide a height here. If providing no delegate, this layout will use auto-sizing, however this causes problems if rotating the device (due to limitaitons in UICollecitonView and autosizing cells that are not visible)
func heightForCell(at indexPath: IndexPath, context: ASWaterfallLayout.CellLayoutContext) -> CGFloat
{
Expand Down
Loading