Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports UICollectionViewCompositionalLayout #87

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions Demo/Book.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ let book = Book(title: "TextureSwiftSupport") {
}

Book.layerBacked()

if #available(iOS 13, *) {

BookPush(title: "CompositionalLayout") {
CollectionNodeCompositionalLayoutViewController()
}
}

BookPush(title: "Transition") {
TransitionLayoutViewController()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import AsyncDisplayKit
import TextureSwiftSupport

@available(iOS 13, *)
final class CollectionNodeCompositionalLayoutViewController: DisplayNodeViewController, ASCollectionDataSource {

let collectionNode: ASCollectionNode

override init() {

let group = NSCollectionLayoutGroup.vertical(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .estimated(1)
),
subitems: [
NSCollectionLayoutItem(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .estimated(1)
)
)
]
)

let section = NSCollectionLayoutSection(group: group)
let layout = UICollectionViewCompositionalLayout.init(section: section)

self.collectionNode = .init(frame: .zero, collectionViewLayout: layout)

super.init()

self.collectionNode.layoutInspector
self.collectionNode.dataSource = self
}

override func viewDidLoad() {
super.viewDidLoad()

}

func numberOfSections(in collectionNode: ASCollectionNode) -> Int {
return 1
}

func collectionNode(_ collectionNode: ASCollectionNode, numberOfItemsInSection section: Int) -> Int {
return 30
}

func collectionNode(_ collectionNode: ASCollectionNode, nodeBlockForItemAt indexPath: IndexPath) -> ASCellNodeBlock {
return {
Self.makeCell()
}
}

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
LayoutSpec {
collectionNode
}
}

static func makeCell() -> ASCellNode {

let label = ASTextNode()
label.attributedText = "Hello".styled(.init())

return WrapperCellNode(
content: AnyDisplayNode { _, _ in
LayoutSpec {
label
.padding(10)
}
}
)

}
}
4 changes: 4 additions & 0 deletions TextureSwiftSupport.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
4B01A3EC2837A8660058F6B8 /* CollectionNodeCompositionalLayoutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B01A3EB2837A8660058F6B8 /* CollectionNodeCompositionalLayoutViewController.swift */; };
4B086A462464434C0024F5A1 /* TextureSwiftSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B086A452464434C0024F5A1 /* TextureSwiftSupport.swift */; };
4B15BCD82667D717006A0D04 /* Book.StyledEdgeNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B15BCD72667D717006A0D04 /* Book.StyledEdgeNode.swift */; };
4B19E610244DD9F0009FD799 /* AnyDisplayNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B19E60F244DD9F0009FD799 /* AnyDisplayNode.swift */; };
Expand Down Expand Up @@ -104,6 +105,7 @@
215C59DB7FDA718082B6AE43 /* Pods-TextureSwiftSupportTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TextureSwiftSupportTests.release.xcconfig"; path = "Target Support Files/Pods-TextureSwiftSupportTests/Pods-TextureSwiftSupportTests.release.xcconfig"; sourceTree = "<group>"; };
36BB5D9261CA6C5AFDF8EB59 /* Pods-Demo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Demo.release.xcconfig"; path = "Target Support Files/Pods-Demo/Pods-Demo.release.xcconfig"; sourceTree = "<group>"; };
3E7680D0CC6B4F2D180803E7 /* Pods-Demo-TextureSwiftSuppoprt.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Demo-TextureSwiftSuppoprt.release.xcconfig"; path = "Target Support Files/Pods-Demo-TextureSwiftSuppoprt/Pods-Demo-TextureSwiftSuppoprt.release.xcconfig"; sourceTree = "<group>"; };
4B01A3EB2837A8660058F6B8 /* CollectionNodeCompositionalLayoutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionNodeCompositionalLayoutViewController.swift; sourceTree = "<group>"; };
4B086A452464434C0024F5A1 /* TextureSwiftSupport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextureSwiftSupport.swift; sourceTree = "<group>"; };
4B15BCD72667D717006A0D04 /* Book.StyledEdgeNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Book.StyledEdgeNode.swift; sourceTree = "<group>"; };
4B19E60F244DD9F0009FD799 /* AnyDisplayNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyDisplayNode.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -446,6 +448,7 @@
4B6FA03A2468B6C900C21A53 /* CompositionCatalogViewController.swift */,
4B2A018225B6E76E00D7C188 /* RecursiveLayoutViewController.swift */,
4B28C83D264FEDF900C1ABA3 /* TransitionLayoutViewController.swift */,
4B01A3EB2837A8660058F6B8 /* CollectionNodeCompositionalLayoutViewController.swift */,
);
path = ViewControllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -765,6 +768,7 @@
4B3C42D6266DCA4F00861ADD /* Book.TiledLayer.swift in Sources */,
4BFE5FE12663DE9400C5C032 /* RootContainerViewController.swift in Sources */,
4B7F1877266745FD002F9A82 /* Book.ImageNode.swift in Sources */,
4B01A3EC2837A8660058F6B8 /* CollectionNodeCompositionalLayoutViewController.swift in Sources */,
4B15BCD82667D717006A0D04 /* Book.StyledEdgeNode.swift in Sources */,
4B28C83E264FEDF900C1ABA3 /* TransitionLayoutViewController.swift in Sources */,
4BC85C1026EFF1B6003BAEAE /* Book.LayerBacking.swift in Sources */,
Expand Down