-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathCollectionNodeCompositionalLayoutViewController.swift
More file actions
77 lines (59 loc) · 1.8 KB
/
CollectionNodeCompositionalLayoutViewController.swift
File metadata and controls
77 lines (59 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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)
}
}
)
}
}