-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathViewAttribute.swift
More file actions
304 lines (260 loc) · 9.63 KB
/
ViewAttribute.swift
File metadata and controls
304 lines (260 loc) · 9.63 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
//
// ViewAttribute.swift
// ViewComposer
//
// Created by Alexander Cyon on 2017-05-31.
//
//
import Foundation
public protocol MarginExpressible {
var margin: Margin { get }
}
extension CGFloat: MarginExpressible {
public var margin: Margin { return Margin(self) }
}
public struct Margin {
let insets: UIEdgeInsets
let isRelative: Bool
public init(top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat, isRelative: Bool = true) {
insets = UIEdgeInsets(top: top, left: left, bottom: bottom, right: right)
self.isRelative = isRelative
}
public init(_ all: CGFloat, isRelative: Bool = true) {
self.init(top: all, left: all, bottom: all, right: all, isRelative: isRelative)
}
public init(vertical: CGFloat, horizontal: CGFloat, isRelative: Bool = true) {
self.init(top: vertical, left: horizontal, bottom: vertical, right: horizontal, isRelative: isRelative)
}
public init(horizontal: CGFloat, isRelative: Bool = true) {
self.init(vertical: 0, horizontal: horizontal, isRelative: isRelative)
}
public init(vertical: CGFloat, isRelative: Bool = true) {
self.init(vertical: vertical, horizontal: 0, isRelative: isRelative)
}
}
extension Margin: MarginExpressible {
public var margin: Margin { return self }
}
public extension Margin {
static func vertical(_ vertical: CGFloat) -> MarginExpressible {
return Margin(vertical: vertical)
}
static func horizontal(_ horizontal: CGFloat) -> MarginExpressible {
return Margin(horizontal: horizontal)
}
}
//swiftlint:disable:next type_body_length
public enum ViewAttribute {
//MARK: - Runtime attributes, not used inside of ViewComposer, you can use these inside runtime methods such as `layoutSubviews` and e.g. using `runtimeTextFieldInset` in the UITextFields method `placeholderRect:forBounds`
case runtimePlaceholderColor(UIColor)
case runtimePlaceholderFont(UIFont)
case runtimeTextFieldInset(CGFloat)
case runtimeTextFieldEdgeInset(CGFloat)
case custom(BaseAttributed)
case delegate(NSObjectProtocol?)
case dataSource(NSObjectProtocol?)
case dataSourceDelegate(NSObjectProtocol?)
//MARK: - View
case hidden(Bool)
case color(UIColor)
case verticalHugging(LayoutPriority)
case verticalCompression(LayoutPriority)
case horizontalHugging(LayoutPriority)
case horizontalCompression(LayoutPriority)
case contentMode(UIViewContentMode)
case height(CGFloat)
case width(CGFloat)
case layoutMargins(all: CGFloat)
case userInteractable(Bool)
case tintColor(UIColor)
case clipsToBounds(Bool)
case alpha(CGFloat)
case opaque(Bool)
case exclusiveTouch(Bool)
case multipleTouchEnabled(Bool)
case clearsContextBeforeDrawing(Bool)
case semanticContentAttribute(UISemanticContentAttribute)
//MARK: - UIView: Layer
case cornerRadius(CGFloat) /* might be overridden by: */; case roundedBy(CornerRounding)
case borderWidth(CGFloat)
case borderColor(UIColor)
//MARK: - TextHolder
case text(String?)
case font(UIFont)
case textColor(UIColor)
case `case`(Case)
case textAlignment(NSTextAlignment)
//MAKR: - FontSizeAdjusting (UILabel + UITextField)
case adjustsFontSizeToFitWidth(Bool)
//MARK: - PlaceholderOwner
case placeholder(String)
//MARK: - TextInputting (UITextField + UITextView)
case editable(Bool)
case clearsOnInsertion(Bool)
case clearsOnBeginEditing(Bool)
case inputView(UIView?)
case inputAccessoryView(UIView?)
case allowsEditingTextAttributes(Bool)
case dataDetectorTypes(UIDataDetectorTypes)
case typingAttributes([String: Any]?)
//MARK: - UILabel
case numberOfLines(Int)
case highlightedTextColor(UIColor)
case minimumScaleFactor(CGFloat)
case baselineAdjustment(UIBaselineAdjustment)
case shadowColor(UIColor)
case shadowOffset(CGSize)
case attributedText(NSAttributedString)
//MARK: UITextInputTraits (UITextField & UISearchBar & UITextView)
case autocapitalizationType(UITextAutocapitalizationType)
case autocorrectionType(UITextAutocorrectionType)
case spellCheckingType(UITextSpellCheckingType)
case keyboardType(UIKeyboardType)
case keyboardAppearance(UIKeyboardAppearance)
case returnKeyType(UIReturnKeyType)
case enablesReturnKeyAutomatically(Bool)
case isSecureTextEntry(Bool)
case textContentType(UITextContentType)
//MARK: UITextField
case borderStyle(UITextBorderStyle)
case background(UIImage?)
case disabledBackground(UIImage?)
case clearButtonMode(UITextFieldViewMode)
case leftView(UIView?)
case leftViewMode(UITextFieldViewMode)
case rightView(UIView?)
case rightViewMode(UITextFieldViewMode)
//MARK: - UITextView
case selectedRange(NSRange)
case linkTextAttributes([String: Any]?)
case textContainerInset(UIEdgeInsets)
//MARK: - ImageHolder
case image(UIImage?)
case highlightedImage(UIImage?)
case renderingMode(UIImageRenderingMode)
case animationImages([UIImage]?)
case highlightedAnimationImages([UIImage]?)
case animationRepeatCount(Int)
case animationDuration(TimeInterval)
//MARK: - UIScrollView
case scrollEnabled(Bool)
case contentSize(CGSize)
case contentInset(UIEdgeInsets)
case bounces(Bool)
case alwaysBounceVertical(Bool)
case alwaysBounceHorizontal(Bool)
case pagingEnabled(Bool)
case showsHorizontalScrollIndicator(Bool)
case showsVerticalScrollIndicator(Bool)
case scrollIndicatorInsets(UIEdgeInsets)
case indicatorStyle(UIScrollViewIndicatorStyle)
case decelerationRate(CGFloat)
case delaysContentTouches(Bool)
case canCancelContentTouches(Bool)
case minimumZoomScale(CGFloat)
case maximumZoomScale(CGFloat)
case zoomScale(CGFloat)
case bouncesZoom(Bool)
case scrollsToTop(Bool)
case keyboardDismissMode(UIScrollViewKeyboardDismissMode)
//MARK: - UIControl
case states([ControlStateStyle])
case contentVerticalAlignment(UIControlContentVerticalAlignment)
case contentHorizontalAlignment(UIControlContentHorizontalAlignment)
case targets([Actor])
public static func target(_ actor: Actor) -> ViewAttribute {
return .targets([actor])
}
case enabled(Bool)
case selected(Bool)
case highlighted(Bool)
//MARK: - UIButton
case contentEdgeInsets(UIEdgeInsets)
case titleEdgeInsets(UIEdgeInsets)
case reversesTitleShadowWhenHighlighted(Bool)
case imageEdgeInsets(UIEdgeInsets)
case adjustsImageWhenHighlighted(Bool)
case adjustsImageWhenDisabled(Bool)
case showsTouchWhenHighlighted(Bool)
//MARK: - UIStackView
case axis(UILayoutConstraintAxis)
case distribution(UIStackViewDistribution)
case alignment(UIStackViewAlignment)
case spacing(CGFloat)
case margin(MarginExpressible)
public static func horizontalMargin(_ horizontal: CGFloat) -> ViewAttribute {
return .margin(Margin.horizontal(horizontal))
}
public static func verticalMargin(_ vertical: CGFloat) -> ViewAttribute {
return .margin(Margin.vertical(vertical))
}
case marginsRelative(Bool)
case baselineRelative(Bool)
case views([UIView?])
//MARK: - CellRegisterable
case registerCells([RegisterableCell])
//MARK: CollectionTableView
case backgroundView(UIView?)
case allowsMultipleSelection(Bool)
case allowsSelection(Bool)
case remembersLastFocusedIndexPath(Bool)
case prefetchDataSource(NSObjectProtocol?)
//MARK: - UITableView
case sectionIndexMinimumDisplayRowCount(Int)
case sectionIndexTrackingBackgroundColor(UIColor?)
case sectionIndexBackgroundColor(UIColor)
case sectionIndexColor(UIColor)
case rowHeight(CGFloat)
case separatorStyle(UITableViewCellSeparatorStyle)
case separatorColor(UIColor?)
case separatorEffect(UIVisualEffect?)
case separatorInset(UIEdgeInsets)
case cellLayoutMarginsFollowReadableWidth(Bool)
case sectionHeaderHeight(CGFloat)
case sectionFooterHeight(CGFloat)
case estimatedRowHeight(CGFloat)
case estimatedSectionHeaderHeight(CGFloat)
case estimatedSectionFooterHeight(CGFloat)
case allowsSelectionDuringEditing(Bool)
case allowsMultipleSelectionDuringEditing(Bool)
case isEditing(Bool)
//MARK: - UICollectionView
case collectionViewLayout(UICollectionViewLayout)
case itemSize(CGSize)
case isPrefetchingEnabled(Bool)
//MARK: - UISearchBar
case prompt(String)
case searchBarStyle(UISearchBarStyle)
//MARK: - UISegmentedControl
case segments([Segment])
//MARK: ThumbTintColorOwner (UISwitch and UISlider)
case thumbTintColor(UIColor?)
//MARK: - UISwitch
case on(Bool)
case onTintColor(UIColor?)
case onImage(UIImage?)
case offImge(UIImage?)
//MARK: WebView
case webPage(URLRequest)
//MARK: - UISlider
case sliderValue(Double)
case sliderRange(Range<Double>)
//MARK: - UIActivityIndicatorView
case spin(Bool)
case hidesWhenStopped(Bool)
case spinnerStyle(UIActivityIndicatorViewStyle)
case spinnerScale(CGFloat)
//MARK: - UIProgressView
case progressViewStyle(UIProgressViewStyle)
case progress(Float)
case progressTintColor(UIColor?)
case progressImage(UIImage?)
case trackTintColor(UIColor?)
case trackImage(UIImage?)
//MARK: - UIPageControl
case currentPage(Int)
case numberOfPages(Int)
case hidesForSinglePage(Bool)
case pageIndicatorTintColor(UIColor)
case currentPageIndicatorTintColor(UIColor)
}