-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathComponents.swift
106 lines (93 loc) · 2.54 KB
/
Components.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import AsyncDisplayKit
import GlossButtonNode
import TextureSwiftSupport
import TypedTextAttributes
import UIKit
enum Components {
static func makeSelectionCell(
title: String,
description: String? = nil,
onTap: @escaping () -> Void
) -> ASCellNode {
let shape = ShapeLayerNode.roundedCorner(radius: 8)
let descriptionLabel = ASTextNode()
descriptionLabel.attributedText = description.map {
NSAttributedString(
string: $0,
attributes: [
.font: UIFont.preferredFont(forTextStyle: .caption1),
.foregroundColor: UIColor.lightGray,
]
)
}
let label = ASTextNode()
label.attributedText = NSAttributedString(
string: title,
attributes: [
.font: UIFont.preferredFont(forTextStyle: .subheadline),
.foregroundColor: UIColor.darkGray,
]
)
return WrapperCellNode(
content: InteractiveNode(
animation: .translucent,
contentNode: AnyDisplayNode { _, _ in
LayoutSpec {
VStackLayout(spacing: 8) {
HStackLayout {
label
.flexGrow(1)
}
if description != nil {
descriptionLabel
}
}
.padding(.horizontal, 8)
.padding(.vertical, 12)
.background(shape)
.padding(4)
}
}
.onDidLoad { _ in
shape.shapeFillColor = .init(white: 0.95, alpha: 1)
}
)
.onTap {
onTap()
}
)
}
static func makeWrapper(_ node: ASDisplayNode) -> ASCellNode {
WrapperCellNode.init(content: node)
}
}
extension GlossButtonNode {
static func simpleButton(title: String, onTap: @escaping () -> Void) -> GlossButtonNode {
let button = GlossButtonNode()
button.onTap = onTap
button.setDescriptor(
.init(
title: title.attributed {
TextAttributes()
.font(.preferredFont(forTextStyle: .headline))
.foregroundColor(.black)
},
image: nil,
bodyStyle: .init(
layout: .horizontal(
imageEdgeInsets: .init(top: 0, left: 0, bottom: 0, right: 4)
),
highlightAnimation: .basic
),
surfaceStyle: .fill(
.init(cornerRound: nil, backgroundColor: nil, dropShadow: nil)
),
bodyOpacity: 1,
insets: .init(top: 10, left: 16, bottom: 10, right: 16),
activityIndicatorStyle: .init()
),
for: .normal
)
return button
}
}