-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathMocks.swift
140 lines (105 loc) · 2.87 KB
/
Mocks.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
// RoundedColorBox.swift
// Demo
//
// Created by muukii on 2020/04/21.
// Copyright © 2020 muukii. All rights reserved.
//
import Foundation
import AsyncDisplayKit
import TextureSwiftSupport
extension UIColor {
// MARK: Public
public convenience init(int hexInt: Int, alpha: CGFloat = 1) {
self.init(
red: CGFloat((hexInt & 0x00FF_0000) >> 16) / 255,
green: CGFloat((hexInt & 0x0000_FF00) >> 8) / 255,
blue: CGFloat((hexInt & 0x0000_00FF) >> 0) / 255,
alpha: alpha
)
}
}
enum Mocks {
static var fillColor: UIColor {
.init(int: 0x157D9D, alpha: 0.2)
}
final class CircularImageNode: WrapperNode<ShapeLayerNode> {
init() {
let node = ShapeLayerNode.capsule(direction: .horizontal, usesSmoothCurve: false)
node.shapeFillColor = fillColor
super.init(content: node)
}
}
final class ImageNode: WrapperNode<ASDisplayNode> {
init() {
let node = ASDisplayNode()
node.backgroundColor = fillColor
super.init(content: node)
}
}
final class SingleLineTextNode: WrapperNode<AnyDisplayNode> {
init() {
let shape = ShapeLayerNode.capsule(direction: .horizontal, usesSmoothCurve: true)
shape.shapeFillColor = fillColor
super.init {
AnyDisplayNode { _, _ in
LayoutSpec {
shape
.frame(width: 120, height: 16)
.padding(2)
}
}
}
}
}
final class ThumbNode: WrapperNode<AnyDisplayNode> {
init() {
let shape = ShapeLayerNode.capsule(direction: .horizontal, usesSmoothCurve: true)
shape.shapeFillColor = fillColor
super.init {
AnyDisplayNode { _, _ in
LayoutSpec {
shape
.frame(width: 20, height: 6)
.padding(2)
}
}
}
}
}
final class ButtonNode: WrapperNode<AnyDisplayNode> {
var onTap: () -> Void = {}
init() {
let shape = ShapeLayerNode.roundedCorner(radius: 8)
shape.shapeFillColor = fillColor
super.init {
AnyDisplayNode { _, _ in
LayoutSpec {
shape
.frame(width: 28, height: 28)
.padding(2)
}
}
}
}
}
final class MultipleLineTextNode: WrapperNode<AnyDisplayNode> {
init(lines: Int) {
let shapes: [ASDisplayNode] = (0..<lines).map { _ in
let node = ShapeLayerNode.capsule(direction: .horizontal, usesSmoothCurve: true)
node.shapeFillColor = fillColor
return node
}
super.init {
AnyDisplayNode { _, _ in
LayoutSpec {
VStackLayout(spacing: 2) {
shapes
.frame(width: 120, height: 16)
}
}
}
}
}
}
}