-
Notifications
You must be signed in to change notification settings - Fork 144
/
Copy pathTypes.swift
213 lines (193 loc) · 8 KB
/
Types.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
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
// Copyright (c) 2018 Luc Dion
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import Foundation
/*
UIView's anchors point
======================
topLeft topCenter topRight
o-------------o--------------o
| |
| |
| |
| |
| |
| center |
centerLeft o o o centerRight
| |
| |
| |
| |
| |
| |
o-------------o--------------o
bottomLeft bottomCenter bottomLeft
*/
/// UIViews's anchor definition
@objc public protocol Anchor {
}
/// UIViews's list of anchors.
@objc public protocol AnchorList {
var topLeft: Anchor { get }
var topCenter: Anchor { get }
var topRight: Anchor { get }
var centerLeft: Anchor { get }
var center: Anchor { get }
var centerRight: Anchor { get }
var bottomLeft: Anchor { get }
var bottomCenter: Anchor { get }
var bottomRight: Anchor { get }
// RTL support
var topStart: Anchor { get }
var topEnd: Anchor { get }
var centerStart: Anchor { get }
var centerEnd: Anchor { get }
var bottomStart: Anchor { get }
var bottomEnd: Anchor { get }
}
/*
UIView's Edges
======================
top
+-----------------+
| |
| |
| hCenter |
left | + | right
| vCenter |
| |
| |
+-----------------+
bottom
*/
/// UIViews's list of edges
@objc public protocol EdgeList {
var top: VerticalEdge { get }
var vCenter: VerticalEdge { get }
var bottom: VerticalEdge { get }
var left: HorizontalEdge { get }
var hCenter: HorizontalEdge { get }
var right: HorizontalEdge { get }
// RTL support
var start: HorizontalEdge { get }
var end: HorizontalEdge { get }
}
/// Horizontal alignment used with relative positioning methods: above(of relativeView:, aligned:), below(of relativeView:, aligned:), ...
///
/// - left: left aligned
/// - center: center aligned
/// - right: right aligned
@objc public enum HorizontalAlign: Int {
/// The view's left edge will be left-aligned with the relative view (or the left most view if a list of relative views is specified).
case left
/// The view's will be horizontally centered with the relative view (or the average hCenter if a list of relative views is used).
case center
/// The view's right edge will be right-aligned with the relative view (or the right most view if a list of relative views is specified).
case right
/// No alignment will be applied.
case none
// RTL support
/// In LTR direction, similar to using HorizontalAlignment.left.
/// In RTL direction, similar to using HorizontalAlignment.right.
case start
/// In LTR direction, similar to using HorizontalAlignment.right.
/// In RTL direction, similar to using HorizontalAlignment.left.
case end
}
/// Vertical alignment used with relative positioning methods: after(of relativeView:, aligned:), before(of relativeView:, aligned:), ...
///
/// - top: top aligned
/// - center: center aligned
/// - bottom: bottom aligned
@objc public enum VerticalAlign: Int {
/// The view's top edge will be top-aligned with the relative view (or the top most view if a list of relative views is specified).
case top
/// The view's will be vertically centered with the relative view (or the average vCenter if a list of relative views is used).
case center
/// The view's bottom edge will be bottom-aligned with the relative view (or the bottom most view if a list of relative views is specified).
case bottom
/// No alignment will be applied.
case none
}
/// UIView's horizontal edges (left/right) definition
@objc public protocol HorizontalEdge {
}
/// UIView's vertical edges (top/bottom) definition
@objc public protocol VerticalEdge {
}
public enum FitType {
/**
**Adjust the view's height** based on the reference width.
* If properties related to the width have been pinned (e.g: width, left & right, margins),
the **reference width will be determined by these properties**, else the **current view's width**
will be used.
* The resulting width will always **match the reference width**.
*/
case width
/**
**Adjust the view's width** based on the reference height.
* If properties related to the height have been pinned (e.g: height, top & bottom, margins),
the reference height will be determined by these properties, else the **current view's height**
will be used.
* The resulting height will always **match the reference height*.
*/
case height
/**
Similar to `.width`, except that PinLayout won't constrain the resulting width to
match the reference width. The resulting width may be smaller of bigger depending on the view's
sizeThatFits(..) method result. For example a single line UILabel may returns a smaller width if its
string is smaller than the reference width.
*/
case widthFlexible
/**
Similar to `.height`, except that PinLayout won't constrain the resulting height to
match the reference height. The resulting height may be smaller or bigger depending on the view's
sizeThatFits(..) method result.
*/
case heightFlexible
/**
Adjust the view's size based on it's content size requirements so that it uses the
most appropriate amount of space. This fit type has the same effect as calling **sizeToFit()** on a view.
The resulting size come from sizeThatFits(..) being called with the current view bounds.
*/
case content
}
@objc public enum WrapType: Int {
/// Adjust the view's width AND height to wrap all its subviews that are included in the size calculation.
case all
/// Adjust only the view's width to wrap all its subviews that are included in the size calculation. The view's height won't be modified.
case horizontally
/// Adjust only the view's height to wrap all its subviews that are included in the size calculation. The view's width won't be modified.
case vertically
}
@objc public enum LayoutDirection: Int {
case auto
case ltr
case rtl
}
/// Control how PinLayout will calls `UIView.safeAreaInsetsDidChange` when the `UIView.pin.safeArea` change.
/// This support is usefull only on iOS 8/9/10. On iOS 11 `UIView.safeAreaInsetsDidChange` is supported
/// natively so this settings have no impact.
@objc public enum PinSafeAreaInsetsDidChangeMode: Int {
/// PinLayout won't call `UIView.safeAreaInsetsDidChange` on iOS 8/9/10.
case disable
/// PinLayout will call `UIView.safeAreaInsetsDidChange` only if the UIView implement the PinSafeAreaInsetsUpdate protocol.
case optIn
/// PinLayout will automatically calls `UIView.safeAreaInsetsDidChange` if the view has implemented this method.
case always
}