From 365f66cbb23a3fbe55893745d941bfa3dbe7d358 Mon Sep 17 00:00:00 2001 From: Muukii Date: Fri, 20 May 2022 20:56:19 +0900 Subject: [PATCH] :zap: WIP --- Demo/Book.swift | 7 ++ ...odeCompositionalLayoutViewController.swift | 77 +++++++++++++++++++ TextureSwiftSupport.xcodeproj/project.pbxproj | 4 + 3 files changed, 88 insertions(+) create mode 100644 Demo/ViewControllers/CollectionNodeCompositionalLayoutViewController.swift diff --git a/Demo/Book.swift b/Demo/Book.swift index 8244743..c3e7d44 100644 --- a/Demo/Book.swift +++ b/Demo/Book.swift @@ -22,6 +22,13 @@ let book = Book(title: "TextureSwiftSupport") { } Book.layerBacked() + + if #available(iOS 13, *) { + + BookPush(title: "CompositionalLayout") { + CollectionNodeCompositionalLayoutViewController() + } + } BookPush(title: "Transition") { TransitionLayoutViewController() diff --git a/Demo/ViewControllers/CollectionNodeCompositionalLayoutViewController.swift b/Demo/ViewControllers/CollectionNodeCompositionalLayoutViewController.swift new file mode 100644 index 0000000..0bb5bf3 --- /dev/null +++ b/Demo/ViewControllers/CollectionNodeCompositionalLayoutViewController.swift @@ -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) + } + } + ) + + } +} diff --git a/TextureSwiftSupport.xcodeproj/project.pbxproj b/TextureSwiftSupport.xcodeproj/project.pbxproj index f683b0d..95b9954 100644 --- a/TextureSwiftSupport.xcodeproj/project.pbxproj +++ b/TextureSwiftSupport.xcodeproj/project.pbxproj @@ -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 */; }; @@ -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 = ""; }; 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 = ""; }; 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 = ""; }; + 4B01A3EB2837A8660058F6B8 /* CollectionNodeCompositionalLayoutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionNodeCompositionalLayoutViewController.swift; sourceTree = ""; }; 4B086A452464434C0024F5A1 /* TextureSwiftSupport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextureSwiftSupport.swift; sourceTree = ""; }; 4B15BCD72667D717006A0D04 /* Book.StyledEdgeNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Book.StyledEdgeNode.swift; sourceTree = ""; }; 4B19E60F244DD9F0009FD799 /* AnyDisplayNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyDisplayNode.swift; sourceTree = ""; }; @@ -446,6 +448,7 @@ 4B6FA03A2468B6C900C21A53 /* CompositionCatalogViewController.swift */, 4B2A018225B6E76E00D7C188 /* RecursiveLayoutViewController.swift */, 4B28C83D264FEDF900C1ABA3 /* TransitionLayoutViewController.swift */, + 4B01A3EB2837A8660058F6B8 /* CollectionNodeCompositionalLayoutViewController.swift */, ); path = ViewControllers; sourceTree = ""; @@ -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 */,