Skip to content

Commit dfeb5a5

Browse files
authored
Merge pull request #169 from layoutBox/fix_swift_3_support
Fix PinLayout Swift 3 support
2 parents 06c1395 + d481640 commit dfeb5a5

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

Sources/PinLayout+Relative.swift

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extension PinLayout {
3939
func context() -> String { return relativeContext("above", relativeViews, aligned) }
4040
return above(relativeViews: relativeViews, aligned: aligned, context: context)
4141
}
42-
42+
4343
//
4444
// below(of ...)
4545
//
@@ -54,7 +54,7 @@ extension PinLayout {
5454
func context() -> String { return relativeContext("below", relativeViews, aligned) }
5555
return below(relativeViews: relativeViews, aligned: aligned, context: context)
5656
}
57-
57+
5858
//
5959
// left(of ...)
6060
//
@@ -134,9 +134,9 @@ extension PinLayout {
134134

135135
// MARK: private
136136
extension PinLayout {
137-
private func above(relativeViews: [View], aligned: HorizontalAlign, context: Context) -> PinLayout {
137+
fileprivate func above(relativeViews: [View], aligned: HorizontalAlign, context: Context) -> PinLayout {
138138
guard let relativeViews = validateRelativeViews(relativeViews, context: context) else { return self }
139-
139+
140140
let anchors: [Anchor]
141141
switch aligned {
142142
case .left: anchors = relativeViews.map({ $0.anchor.topLeft })
@@ -154,9 +154,9 @@ extension PinLayout {
154154
return self
155155
}
156156

157-
private func below(relativeViews: [View], aligned: HorizontalAlign, context: Context) -> PinLayout {
157+
fileprivate func below(relativeViews: [View], aligned: HorizontalAlign, context: Context) -> PinLayout {
158158
guard let relativeViews = validateRelativeViews(relativeViews, context: context) else { return self }
159-
159+
160160
let anchors: [Anchor]
161161
switch aligned {
162162
case .left: anchors = relativeViews.map({ $0.anchor.bottomLeft })
@@ -173,10 +173,10 @@ extension PinLayout {
173173
}
174174
return self
175175
}
176-
177-
private func left(relativeViews: [View], aligned: VerticalAlign, context: Context) -> PinLayout {
176+
177+
fileprivate func left(relativeViews: [View], aligned: VerticalAlign, context: Context) -> PinLayout {
178178
guard let relativeViews = validateRelativeViews(relativeViews, context: context) else { return self }
179-
179+
180180
let anchors: [Anchor]
181181
switch aligned {
182182
case .top: anchors = relativeViews.map({ $0.anchor.topLeft })
@@ -191,25 +191,25 @@ extension PinLayout {
191191
}
192192
return self
193193
}
194-
195-
private func right(relativeViews: [View], aligned: VerticalAlign, context: Context) -> PinLayout {
194+
195+
fileprivate func right(relativeViews: [View], aligned: VerticalAlign, context: Context) -> PinLayout {
196196
guard let relativeViews = validateRelativeViews(relativeViews, context: context) else { return self }
197-
197+
198198
let anchors: [Anchor]
199199
switch aligned {
200200
case .top: anchors = relativeViews.map({ $0.anchor.topRight })
201201
case .center: anchors = relativeViews.map({ $0.anchor.centerRight })
202202
case .bottom: anchors = relativeViews.map({ $0.anchor.bottomRight })
203203
case .none: anchors = relativeViews.map({ $0.anchor.topRight })
204204
}
205-
205+
206206
if let coordinatesList = computeCoordinates(forAnchors: anchors, context) {
207207
setLeft(getRightMostCoordinate(list: coordinatesList), context)
208208
applyVerticalAlignment(aligned, coordinatesList: coordinatesList, context: context)
209209
}
210210
return self
211211
}
212-
212+
213213
private func applyHorizontalAlignment(_ aligned: HorizontalAlign?, coordinatesList: [CGPoint], context: Context) {
214214
guard let aligned = aligned, aligned != .none else { return }
215215
switch aligned {
@@ -225,7 +225,7 @@ extension PinLayout {
225225
case .none: break
226226
}
227227
}
228-
228+
229229
private func applyVerticalAlignment(_ aligned: VerticalAlign?, coordinatesList: [CGPoint], context: Context) {
230230
guard let aligned = aligned, aligned != .none else { return }
231231
switch aligned {
@@ -235,78 +235,78 @@ extension PinLayout {
235235
case .none: break
236236
}
237237
}
238-
238+
239239
private func getTopMostCoordinate(list: [CGPoint]) -> CGFloat {
240240
assert(list.count > 0)
241241
let firstCoordinate = list[0].y
242242
return list.dropFirst().reduce(firstCoordinate, { (bestCoordinate, otherCoordinates) -> CGFloat in
243243
return (otherCoordinates.y < bestCoordinate) ? otherCoordinates.y : bestCoordinate
244244
})
245245
}
246-
246+
247247
private func getBottomMostCoordinate(list: [CGPoint]) -> CGFloat {
248248
assert(list.count > 0)
249249
let firstCoordinate = list[0].y
250250
return list.dropFirst().reduce(firstCoordinate, { (bestCoordinate, otherCoordinates) -> CGFloat in
251251
return (otherCoordinates.y > bestCoordinate) ? otherCoordinates.y : bestCoordinate
252252
})
253253
}
254-
254+
255255
private func getLeftMostCoordinate(list: [CGPoint]) -> CGFloat {
256256
assert(list.count > 0)
257257
let firstCoordinate = list[0].x
258258
return list.dropFirst().reduce(firstCoordinate, { (bestCoordinate, otherCoordinates) -> CGFloat in
259259
return (otherCoordinates.x < bestCoordinate) ? otherCoordinates.x : bestCoordinate
260260
})
261261
}
262-
262+
263263
private func getRightMostCoordinate(list: [CGPoint]) -> CGFloat {
264264
assert(list.count > 0)
265265
let firstCoordinate = list[0].x
266266
return list.dropFirst().reduce(firstCoordinate, { (bestCoordinate, otherCoordinates) -> CGFloat in
267267
return (otherCoordinates.x > bestCoordinate) ? otherCoordinates.x : bestCoordinate
268268
})
269269
}
270-
270+
271271
private func getAverageHCenterCoordinate(list: [CGPoint]) -> CGFloat {
272272
assert(list.count > 0)
273273
let sum = list.reduce(0, { (result, point) -> CGFloat in
274274
return result + point.x
275275
})
276276
return sum / CGFloat(list.count)
277277
}
278-
278+
279279
private func getAverageVCenterCoordinate(list: [CGPoint]) -> CGFloat {
280280
assert(list.count > 0)
281281
let sum = list.reduce(0, { (result, point) -> CGFloat in
282282
return result + point.y
283283
})
284284
return sum / CGFloat(list.count)
285285
}
286-
286+
287287
private func validateRelativeViews(_ relativeViews: [View], context: Context) -> [View]? {
288288
guard let _ = layoutSuperview(context) else { return nil }
289289
guard relativeViews.count > 0 else {
290290
warnWontBeApplied("At least one view must be visible (i.e. UIView.isHidden != true) ", context)
291291
return nil
292292
}
293-
293+
294294
return relativeViews
295295
}
296296

297-
private func relativeContext(_ type: String, _ relativeView: View, _ aligned: VerticalAlign?) -> String {
297+
fileprivate func relativeContext(_ type: String, _ relativeView: View, _ aligned: VerticalAlign?) -> String {
298298
return relativeContext(type, "\(relativeView)", aligned: aligned == VerticalAlign.none ? nil : aligned?.description)
299299
}
300300

301-
private func relativeContext(_ type: String, _ relativeViews: [View], _ aligned: VerticalAlign?) -> String {
301+
fileprivate func relativeContext(_ type: String, _ relativeViews: [View], _ aligned: VerticalAlign?) -> String {
302302
return relativeContext(type, "\(relativeViews)", aligned: aligned == VerticalAlign.none ? nil : aligned?.description)
303303
}
304304

305-
private func relativeContext(_ type: String, _ relativeView: View, _ aligned: HorizontalAlign?) -> String {
305+
fileprivate func relativeContext(_ type: String, _ relativeView: View, _ aligned: HorizontalAlign?) -> String {
306306
return relativeContext(type, "\(relativeView)", aligned: aligned == HorizontalAlign.none ? nil : aligned?.description)
307307
}
308308

309-
private func relativeContext(_ type: String, _ relativeViews: [View], _ aligned: HorizontalAlign?) -> String {
309+
fileprivate func relativeContext(_ type: String, _ relativeViews: [View], _ aligned: HorizontalAlign?) -> String {
310310
return relativeContext(type, "\(relativeViews)", aligned: aligned == HorizontalAlign.none ? nil : aligned?.description)
311311
}
312312

0 commit comments

Comments
 (0)