Skip to content

Commit 777832d

Browse files
author
Luc Dion
committed
fitSize() has been removed after being deprecated for 10 months. sizeToFit(...) should now be used instead.
Plus: * Refactor relative positioning methods source code (above(...), after(...), ...) using a default parameter value for the alignment parameter. * Fix unit test screen density. * Update few examples source code.
1 parent 542b1b5 commit 777832d

17 files changed

+200
-270
lines changed

Example/PinLayoutSample/UI/Common/BasicView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class BasicView: UIView {
4343
override func layoutSubviews() {
4444
super.layoutSubviews()
4545

46-
label.pin.top().left().right().margin(4).sizeToFit(.width)
46+
label.pin.top().horizontally().margin(4).sizeToFit(.width)
4747
}
4848

4949
var sizeThatFitsExpectedArea: CGFloat = 40 * 40

Example/PinLayoutSample/UI/Examples/MultiRelativeView/MultiRelativeView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MultiRelativeView: UIView {
4444

4545
view1.pin.top(pin.safeArea).left(pin.safeArea).width(20%).height(50%)
4646
view2.pin.top(pin.safeArea).right(pin.safeArea).width(20%).height(50%)
47-
48-
view.pin.right(of: view1, aligned: .top).left(of: view2, aligned: .bottom).marginHorizontal(10)
47+
48+
view.pin.after(of: view1, aligned: .top).before(of: view2, aligned: .bottom).marginHorizontal(10)
4949
}
5050
}

Example/PinLayoutSample/UI/Examples/RelativeView/RelativeView.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ class RelativeView: UIView {
8585
topCenterView.pin.above(of: centerView, aligned: .center).marginBottom(10)
8686
topRightView.pin.above(of: centerView, aligned: .right).marginBottom(10)
8787

88-
rightTopView.pin.right(of: centerView, aligned: .top).marginLeft(10)
89-
rightCenterView.pin.right(of: centerView, aligned: .center).marginLeft(10)
90-
rightBottomView.pin.right(of: centerView, aligned: .bottom).marginLeft(10)
88+
rightTopView.pin.after(of: centerView, aligned: .top).marginLeft(10)
89+
rightCenterView.pin.after(of: centerView, aligned: .center).marginLeft(10)
90+
rightBottomView.pin.after(of: centerView, aligned: .bottom).marginLeft(10)
9191

9292
bottomLeftView.pin.below(of: centerView, aligned: .left).marginTop(10)
9393
bottomCenterView.pin.below(of: centerView, aligned: .center).marginTop(10)
9494
bottomRightView.pin.below(of: centerView, aligned: .right).marginTop(10)
9595

96-
leftTopView.pin.left(of: centerView, aligned: .top).marginRight(10)
97-
leftCenterView.pin.left(of: centerView, aligned: .center).marginRight(10)
98-
leftBottomView.pin.left(of: centerView, aligned: .bottom).marginRight(10)
96+
leftTopView.pin.before(of: centerView, aligned: .top).marginRight(10)
97+
leftCenterView.pin.before(of: centerView, aligned: .center).marginRight(10)
98+
leftBottomView.pin.before(of: centerView, aligned: .bottom).marginRight(10)
9999
}
100100
}

Example/PinLayoutSample/UI/Examples/TableViewExample/Cells/MethodCell.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class MethodCell: UITableViewCell {
6161

6262
private func layout() {
6363
iconImageView.pin.top().left().size(30).margin(padding)
64-
nameLabel.pin.right(of: iconImageView, aligned: .center).right().marginHorizontal(padding).sizeToFit(.width)
64+
nameLabel.pin.after(of: iconImageView, aligned: .center).right().marginHorizontal(padding).sizeToFit(.width)
6565
descriptionLabel.pin.below(of: [iconImageView, nameLabel]).horizontally().margin(padding).sizeToFit(.width)
6666
}
6767

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 Luc Dion
3+
Copyright (c) 2017-2018 Luc Dion
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

PinLayout.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |spec|
1010
spec.name = "PinLayout"
11-
spec.version = "1.7.12"
11+
spec.version = "1.8.0"
1212
spec.summary = "Fast Swift Views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable. [iOS/macOS/tvOS/CALayer]"
1313
spec.description = "Fast Swift Views layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable. [iOS/macOS/tvOS/CALayer]"
1414
spec.homepage = "https://github.com/layoutBox/PinLayout"

Podfile.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
PODS:
22
- Nimble (7.0.3)
3-
- PinLayout (1.7.11)
3+
- PinLayout (1.7.12)
44
- Quick (1.2.0)
55
- Reveal-SDK (17)
6-
- SwiftLint (0.25.1)
6+
- SwiftLint (0.27.0)
77

88
DEPENDENCIES:
99
- Nimble
@@ -13,7 +13,7 @@ DEPENDENCIES:
1313
- SwiftLint
1414

1515
SPEC REPOS:
16-
https://github.com/CocoaPods/Specs.git:
16+
https://github.com/cocoapods/specs.git:
1717
- Nimble
1818
- Quick
1919
- Reveal-SDK
@@ -25,11 +25,11 @@ EXTERNAL SOURCES:
2525

2626
SPEC CHECKSUMS:
2727
Nimble: 7f5a9c447a33002645a071bddafbfb24ea70e0ac
28-
PinLayout: 90c26ecc9504e35c6569a65d78dc50853d96f08c
28+
PinLayout: 4922b1c70da60d5bff2e7fb4116deb1ddc759927
2929
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08
3030
Reveal-SDK: a6df49f47319bd19a110c960c498af32df72c0af
31-
SwiftLint: ce933681be10c3266e82576dad676fa815a602e9
31+
SwiftLint: 3207c1faa2240bf8973b191820a116113cd11073
3232

3333
PODFILE CHECKSUM: 62618887f8155abc1ed3348d9b676cf6915137e2
3434

35-
COCOAPODS: 1.5.0
35+
COCOAPODS: 1.5.3

README.md

+19-11
Original file line numberDiff line numberDiff line change
@@ -474,20 +474,24 @@ Position the view left of the specified view(s) and aligned it using the specifi
474474
Position the view right of the specified view(s) and aligned it using the specified VerticalAlignment. Similar to `after(of:)`. One or many relative views can be specified. This method is similar to pinning one view’s anchor: topLeft, centerLeft or bottomLeft.
475475

476476

477-
**How alignment is applied:**
477+
**How HorizontalAlignment is applied:**
478478

479-
* **`HorizontalAlignment.left`**: The view's left edge will be aligned to the left most relative view.
480-
* **`HorizontalAlignment.center`**: The view's hCenter edge will be aligned with the average hCenter of all relative views.
481-
* **`HorizontalAlignment.right`**: The view's right edge will be aligned to the right most relative view.
479+
* **`HorizontalAlignment.left`**: 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).
480+
* **`HorizontalAlignment.center`**: The view's will be horizontally centered with the relative view (or the average hCenter if a list of relative views is used).
481+
* **`HorizontalAlignment.right`**: 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).
482482
* **`HorizontalAlignment.start`**:left_right_arrow::
483-
In LTR direction the view's left edge will be aligned to the left most relative view.
484-
In RTL direction the view's right edge will be aligned to the right most relative view.
483+
In LTR direction, similar to using HorizontalAlignment.left.
484+
In RTL direction, similar to using HorizontalAlignment.right.
485485
* **`HorizontalAlignment.end`**:left_right_arrow::
486-
In LTR direction the view's right edge will be aligned to the right most relative view.
487-
In RTL direction the view's left edge will be aligned to the right most relative view.
488-
* **`VerticalAlignment.top`**: The view's top edge will be aligned to the top most relative view.
489-
* **`VerticalAlignment.center`**: The view's vCenter edge will be aligned with the average vCenter of all relative views.
490-
* **`VerticalAlignment.bottom`**: The view's bottom edge will be aligned to the bottom most relative view.
486+
In LTR direction, similar to using HorizontalAlignment.right.
487+
In RTL direction, similar to using HorizontalAlignment.left.
488+
489+
**How VerticalAlignment is applied:**
490+
491+
492+
* **`VerticalAlignment.top`**: 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).
493+
* **`VerticalAlignment.center`**: The view's will be vertically centered with the relative view (or the average vCenter if a list of relative views is used).
494+
* **`VerticalAlignment.bottom`**: 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).
491495

492496
:pushpin: **Multiple relative views**: If for example a call to `below(of: [...], aligned:) specify multiple relative views, the view will be layouted below *ALL* these views. The alignment will be applied using all relative view
493497

@@ -1727,6 +1731,10 @@ PinLayout was inspired by other great layout frameworks, including:
17271731
## History
17281732
PinLayout recent history is available in the [CHANGELOG](CHANGELOG.md) also in [GitHub Releases](https://github.com/layoutBox/PinLayout/releases).
17291733

1734+
### Recent breaking change
1735+
1736+
* `fitSize()` has been removed after being deprecated for 10 months. `sizeToFit(...)` should now be used instead. See [Adjusting size](#adjusting_size). (2018-08-21)
1737+
17301738
<br>
17311739

17321740
## License

Sources/Impl/Coordinates.swift

+10-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,16 @@ internal var displayScale: CGFloat = NSScreen.main?.backingScaleFactor ?? 2.0
3030
#endif
3131
internal var onePixelLength: CGFloat = 1 / displayScale
3232

33-
public func _pinlayoutSetUnitTest(scale: CGFloat) {
34-
displayScale = scale
33+
public func _pinlayoutSetUnitTest(scale: CGFloat?) {
34+
if let scale = scale {
35+
displayScale = scale
36+
} else {
37+
#if os(iOS) || os(tvOS)
38+
displayScale = UIScreen.main.scale
39+
#elseif os(OSX)
40+
displayScale = NSScreen.main?.backingScaleFactor ?? 2.0
41+
#endif
42+
}
3543
}
3644

3745
final class Coordinates<View: Layoutable> {

Sources/Impl/PinLayout+Layouting.swift

+6-42
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ extension PinLayout {
203203
size = computeSizeToFit(adjustSizeType: adjustSizeType, size: size)
204204
case .sizeToFit:
205205
size = computeSizeToFit(size: size)
206-
case .fitSizeLegacy:
207-
size = computeLegacyFitSize(size: size)
208206
case .aspectRatio(let ratio):
209207
size = computeAspectRatio(ratio, size: size)
210208
}
@@ -249,44 +247,6 @@ extension PinLayout {
249247
return Size(width: viewRect.width, height: viewRect.height)
250248
}
251249

252-
private func computeLegacyFitSize(size: Size) -> Size {
253-
guard let sizeCalculableView = view as? SizeCalculable else {
254-
assertionFailure("Should not occurs, protocol conformance is checked before assigning adjustSizeType")
255-
return size
256-
}
257-
guard size.width != nil || size.height != nil else {
258-
warn("fitSize() won't be applied, neither the width nor the height can be determined.")
259-
return size
260-
}
261-
262-
var size = size
263-
var fitWidth = CGFloat.greatestFiniteMagnitude
264-
var fitHeight = CGFloat.greatestFiniteMagnitude
265-
266-
if let width = applyMinMax(toWidth: size.width) {
267-
fitWidth = width
268-
}
269-
if let height = applyMinMax(toHeight: size.height) {
270-
fitHeight = height
271-
}
272-
273-
let sizeThatFits = sizeCalculableView.sizeThatFits(CGSize(width: fitWidth, height: fitHeight))
274-
275-
if fitWidth != .greatestFiniteMagnitude && (sizeThatFits.width > fitWidth) {
276-
size.width = fitWidth
277-
} else {
278-
size.width = sizeThatFits.width
279-
}
280-
281-
if fitHeight != .greatestFiniteMagnitude && (sizeThatFits.height > fitHeight) {
282-
size.height = fitHeight
283-
} else {
284-
size.height = sizeThatFits.height
285-
}
286-
287-
return size
288-
}
289-
290250
private func computeSizeToFit(adjustSizeType: AdjustSizeType, size: Size) -> Size {
291251
guard let sizeCalculableView = view as? SizeCalculable else {
292252
assertionFailure("Should not occurs, protocol conformance is checked before assigning adjustSizeType")
@@ -389,7 +349,7 @@ extension PinLayout {
389349
let remainingWidth = containerWidth - rect.width
390350
var justifyType = HorizontalAlign.left
391351

392-
if let justify = justify {
352+
if let justify = justify, justify != .none {
393353
justifyType = justify
394354
}
395355

@@ -415,6 +375,8 @@ extension PinLayout {
415375
} else {
416376
rect.origin.x = left + _marginLeft
417377
}
378+
case .none:
379+
break
418380
}
419381

420382
return rect
@@ -441,7 +403,7 @@ extension PinLayout {
441403
let remainingHeight = containerHeight - rect.height
442404
var alignType = VerticalAlign.top
443405

444-
if let align = align {
406+
if let align = align, align != .none {
445407
alignType = align
446408
}
447409

@@ -454,6 +416,8 @@ extension PinLayout {
454416
rect.origin.y = top + _marginTop + remainingHeight / 2
455417
case .bottom:
456418
rect.origin.y = bottom - _marginBottom - rect.height
419+
case .none:
420+
break
457421
}
458422

459423
return rect

0 commit comments

Comments
 (0)