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

Commit

Permalink
1.7.1 (#153)
Browse files Browse the repository at this point in the history
- Workaround for SwiftUI bug (viewDidAppear not being called inside scrollView)
  • Loading branch information
apptekstudios authored Jun 3, 2020
1 parent e71eda8 commit 4550cd5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 55 deletions.
2 changes: 1 addition & 1 deletion 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.7.0'
s.version = '1.7.1'
s.summary = 'A SwiftUI collection view with support for custom layouts, preloading, and more. '

s.description = <<-DESC
Expand Down
8 changes: 0 additions & 8 deletions Demo/ASCollectionViewDemo/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ struct MainView: View
Text("Multiple TableView drag&drop")
}
}
Section(header: Text("Modified examples"))
{
NavigationLink(destination: TagsScreen(shrinkToSize: true))
{
Image(systemName: "hammer")
Text("Tags in self-sizing collection")
}
}
}
.navigationBarTitle("Demo App")
}
Expand Down
85 changes: 40 additions & 45 deletions Demo/ASCollectionViewDemo/Screens/Tags/TagsScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,60 @@ struct TagsScreen: View
{
@ObservedObject var store = TagStore()

/// Used in the extra example that shrinks the collectionView to fit its content
var shrinkToSize: Bool = false
@State var contentSize: CGSize? // This state variable is handed to the collectionView to allow it to store the content size
///

var body: some View
{
VStack(alignment: .leading, spacing: 20)
{
HStack
ScrollView(.vertical) {
VStack(alignment: .leading, spacing: 20)
{
Spacer()
Text("Tap this button to reload new tags")
Text("This screen has an ASCollectionView embedded into a SwiftUI scrollview")
.multilineTextAlignment(.center)
.fixedSize(horizontal: false, vertical: true)
.frame(maxWidth: .infinity)
.padding()
.background(Color(.secondarySystemBackground))
Spacer()
}
.onTapGesture
{
withAnimation(self.shrinkToSize ? nil : .default) {
HStack
{
Spacer()
Text("Tap this button to reload new tags")
.padding()
.background(Color(.secondarySystemBackground))
Spacer()
}
.onTapGesture
{
self.store.refreshStore()
}
}
Text("Tags:")
.font(.title)

ASCollectionView(
section:
ASCollectionViewSection(id: 0, data: store.items)
{ item, _ in
Text(item.displayString)
.fixedSize(horizontal: false, vertical: true)
.padding(5)
.background(Color(.systemGray))
.cornerRadius(5)
}.selfSizingConfig { _ in
ASSelfSizingConfig(canExceedCollectionWidth: false)
Text("Tags:")
.font(.title)

ASCollectionView(
section:
ASCollectionViewSection(id: 0, data: store.items)
{ item, _ in
Text(item.displayString)
.fixedSize(horizontal: false, vertical: true)
.padding(5)
.background(Color(.systemGray))
.cornerRadius(5)
}.selfSizingConfig { _ in
ASSelfSizingConfig(canExceedCollectionWidth: false)
}
)
.layout
{
let fl = AlignedFlowLayout()
fl.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
return fl
}
)
.layout
{
let fl = AlignedFlowLayout()
fl.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
return fl
}
.shrinkToContentSize(isEnabled: shrinkToSize, dimension: .vertical)

if shrinkToSize
{
.fitContentSize(dimension: .vertical)
Text("This is another view in the VStack, it shows how the collectionView above fits itself to the content.")
.padding()
.frame(idealWidth: .infinity, maxWidth: .infinity)
.frame(maxWidth: .infinity)
.foregroundColor(Color(.secondaryLabel))
.fixedSize(horizontal: false, vertical: true)
.background(Color(.secondarySystemBackground))
Spacer()
}
.padding()
}
.padding()
.navigationBarTitle("Tags", displayMode: .inline)
}
}
Expand Down
16 changes: 15 additions & 1 deletion Sources/ASCollectionView/UIKit/AS_UICollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ import SwiftUI
public class AS_CollectionViewController: UIViewController
{
weak var coordinator: ASCollectionViewCoordinator?
{
didSet
{
collectionView.coordinator = coordinator
}
}

var collectionViewLayout: UICollectionViewLayout
lazy var collectionView: AS_UICollectionView = {
let cv = AS_UICollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
cv.coordinator = coordinator
return cv
}()

Expand Down Expand Up @@ -95,4 +102,11 @@ public class AS_CollectionViewController: UIViewController
}

@available(iOS 13.0, *)
class AS_UICollectionView: UICollectionView {}
class AS_UICollectionView: UICollectionView
{
weak var coordinator: ASCollectionViewCoordinator?
override func didMoveToSuperview()
{
if superview != nil { coordinator?.onMoveToParent() }
}
}

0 comments on commit 4550cd5

Please sign in to comment.