/
CollectionExample.swift
66 lines (58 loc) · 1.38 KB
/
CollectionExample.swift
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
//
// CollectionExample.swift
// TokamakDemo
//
// Created by Matvii Hodovaniuk on 3/7/19.
// Copyright © 2019 Tokamak. All rights reserved.
//
import Tokamak
enum ElementaryParticles: String, CaseIterable {
case up
case down
case charm
case strange
case top
case bottom
case gluon
case photon
case higs
case electron
case muon
case tau
case electronNeutrino = "Electron Neutrino"
case muonNeutrino = "Muon Neutrino"
case tauNeutrino = "Tau Neutrino"
case zBoson = "Z Boson"
case wBoson = "W Boson"
}
extension ElementaryParticles: CustomStringConvertible {
var description: String { return rawValue.localizedCapitalized }
}
private struct Cells: SimpleCellProvider {
static func cell(
props: Null,
item: ElementaryParticles,
path: CellPath
) -> AnyNode {
return Label.node(.init(Style(
[CenterY.equal(to: .parent),
Height.equal(to: 44),
Leading.equal(to: .parent),
Trailing.equal(to: .parent)]
)), "\(item.description)")
}
typealias Props = Null
typealias Model = [[ElementaryParticles]]
}
struct CollectionExample: PureLeafComponent {
typealias Props = Null
static func render(props: Props) -> AnyNode {
return CollectionView<Cells>.node(.init(
Style(
Edges.equal(to: .parent, inset: 20),
backgroundColor: .white
),
model: [ElementaryParticles.allCases]
))
}
}