Skip to content

Commit 1dfcc68

Browse files
committed
updated the center to use center the view and not honor the layout guide
1 parent b82b035 commit 1dfcc68

6 files changed

Lines changed: 39 additions & 28 deletions

File tree

PinLayout/Main/Source/Layout_SafeCenter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extension Layout {
3030
guard let otherView = self.otherView(view: view, other: other) else {
3131
return nil
3232
}
33-
let constraint = view.safeAreaLayoutGuide.centerXAnchor.constraint(equalTo: otherView.safeAreaLayoutGuide.centerXAnchor)
33+
let constraint = view.centerXAnchor.constraint(equalTo: otherView.centerXAnchor)
3434
constraint.isActive = true
3535
constraint.constant = offset
3636
constraint.priority = priority
@@ -49,7 +49,7 @@ extension Layout {
4949
guard let otherView = self.otherView(view: view, other: other) else {
5050
return nil
5151
}
52-
let constraint = view.safeAreaLayoutGuide.centerYAnchor.constraint(equalTo: otherView.safeAreaLayoutGuide.centerYAnchor)
52+
let constraint = view.centerYAnchor.constraint(equalTo: otherView.centerYAnchor)
5353
constraint.isActive = true
5454
constraint.constant = offset
5555
constraint.priority = priority

PinLayout/Test/Source/LayoutBuilder_Test.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ class LayoutBuilder_Test: PinLayout_Base_Test {
223223
// then
224224
assertThat(constraint, present())
225225
assertThat(constraint?.firstAttribute, equalTo(.centerX))
226-
assertThat(constraint?.firstItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(view.safeAreaLayoutGuide))))
226+
assertThat(constraint?.firstItem, presentAnd(instanceOf(UIView.self, and:equalTo(view))))
227227
assertThat(constraint?.secondAttribute, presentAnd(equalTo(.centerX)))
228-
assertThat(constraint?.secondItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(superview.safeAreaLayoutGuide))))
228+
assertThat(constraint?.secondItem, presentAnd(instanceOf(UIView.self, and:equalTo(superview))))
229229
assertThat(constraint?.constant, presentAnd(equalTo(0)))
230230
assertThat(constraint?.isActive, presentAnd(equalTo(true)))
231231
assertThat(view.translatesAutoresizingMaskIntoConstraints, equalTo(false))
@@ -265,9 +265,9 @@ class LayoutBuilder_Test: PinLayout_Base_Test {
265265
// then
266266
assertThat(constraint, present())
267267
assertThat(constraint?.firstAttribute, equalTo(.centerX))
268-
assertThat(constraint?.firstItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(view.safeAreaLayoutGuide))))
268+
assertThat(constraint?.firstItem, presentAnd(instanceOf(UIView.self, and:equalTo(view))))
269269
assertThat(constraint?.secondAttribute, presentAnd(equalTo(.centerX)))
270-
assertThat(constraint?.secondItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(other.safeAreaLayoutGuide))))
270+
assertThat(constraint?.secondItem, presentAnd(instanceOf(UIView.self, and:equalTo(other))))
271271
assertThat(constraint?.constant, presentAnd(equalTo(0)))
272272
assertThat(constraint?.isActive, presentAnd(equalTo(true)))
273273
assertThat(view.translatesAutoresizingMaskIntoConstraints, equalTo(false))
@@ -283,9 +283,9 @@ class LayoutBuilder_Test: PinLayout_Base_Test {
283283
// then
284284
assertThat(constraint, present())
285285
assertThat(constraint?.firstAttribute, equalTo(.centerY))
286-
assertThat(constraint?.firstItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(view.safeAreaLayoutGuide))))
286+
assertThat(constraint?.firstItem, presentAnd(instanceOf(UIView.self, and:equalTo(view))))
287287
assertThat(constraint?.secondAttribute, presentAnd(equalTo(.centerY)))
288-
assertThat(constraint?.secondItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(superview.safeAreaLayoutGuide))))
288+
assertThat(constraint?.secondItem, presentAnd(instanceOf(UIView.self, and:equalTo(superview))))
289289
assertThat(constraint?.constant, presentAnd(equalTo(0)))
290290
assertThat(constraint?.isActive, presentAnd(equalTo(true)))
291291
assertThat(view.translatesAutoresizingMaskIntoConstraints, equalTo(false))
@@ -327,9 +327,9 @@ class LayoutBuilder_Test: PinLayout_Base_Test {
327327
// then
328328
assertThat(constraint, present())
329329
assertThat(constraint?.firstAttribute, equalTo(.centerY))
330-
assertThat(constraint?.firstItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(view.safeAreaLayoutGuide))))
330+
assertThat(constraint?.firstItem, presentAnd(instanceOf(UIView.self, and:equalTo(view))))
331331
assertThat(constraint?.secondAttribute, presentAnd(equalTo(.centerY)))
332-
assertThat(constraint?.secondItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(other.safeAreaLayoutGuide))))
332+
assertThat(constraint?.secondItem, presentAnd(instanceOf(UIView.self, and:equalTo(other))))
333333
assertThat(constraint?.constant, presentAnd(equalTo(0)))
334334
assertThat(constraint?.isActive, presentAnd(equalTo(true)))
335335
assertThat(view.translatesAutoresizingMaskIntoConstraints, equalTo(false))
@@ -350,12 +350,12 @@ class LayoutBuilder_Test: PinLayout_Base_Test {
350350
assertThat(constraints.first?.firstAttribute, equalTo(.centerX))
351351
assertThat(constraints.last?.firstAttribute, equalTo(.centerY))
352352

353-
assertThat(constraints.first?.secondItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(superview.safeAreaLayoutGuide))))
354-
assertThat(constraints.last?.secondItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(superview.safeAreaLayoutGuide))))
353+
assertThat(constraints.first?.secondItem, presentAnd(instanceOf(UIView.self, and:equalTo(superview))))
354+
assertThat(constraints.last?.secondItem, presentAnd(instanceOf(UIView.self, and:equalTo(superview))))
355355
}
356356

357357

358-
func test_saveArea_center_to_other() {
358+
func test_center_to_other() {
359359
let superview = UIView()
360360
let other = UIView()
361361
superview.addSubview(view)
@@ -368,8 +368,8 @@ class LayoutBuilder_Test: PinLayout_Base_Test {
368368
assertThat(constraints.first?.firstAttribute, equalTo(.centerX))
369369
assertThat(constraints.last?.firstAttribute, equalTo(.centerY))
370370

371-
assertThat(constraints.first?.secondItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(other.safeAreaLayoutGuide))))
372-
assertThat(constraints.last?.secondItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(other.safeAreaLayoutGuide))))
371+
assertThat(constraints.first?.secondItem, presentAnd(instanceOfAnd(equalTo(other))))
372+
assertThat(constraints.last?.secondItem, presentAnd(instanceOfAnd(equalTo(other))))
373373
}
374374

375375

PinLayout/Test/Source/PinLayout_AutoResizing_Test.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ struct PinLayout_AutoResizing_SwiftTest {
1515
let view = UIView()
1616
let toView = UIView()
1717
let pinLayout = Layout()
18+
19+
init() async throws {
20+
HamcrestSwiftTesting.enable()
21+
}
1822

1923

2024
@Test func disables_translatesAutoresizingMaskIntoConstraints() {

PinLayout/Test/Source/PinLayout_Center_Test.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import PinLayout
1515

1616
@MainActor
1717
struct PinLayout_Center_Test {
18+
init() async throws {
19+
HamcrestSwiftTesting.enable()
20+
}
21+
1822
let view = UIView()
1923
let pinLayout = Layout()
2024

PinLayout/Test/Source/PinLayout_Defaults_Test.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import HamcrestSwiftTesting
1111
import PinLayout
1212

1313
struct PinLayout_Defaults_Test {
14-
14+
init() async throws {
15+
HamcrestSwiftTesting.enable()
16+
}
17+
1518
let pinLayout = Layout()
1619

1720

PinLayout/Test/Source/PinLayout_Safe_Center.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class PinLayout_Safe_Center: PinLayout_Base_Test {
2424
// then
2525
assertThat(constraint, present())
2626
assertThat(constraint?.firstAttribute, equalTo(.centerX))
27-
assertThat(constraint?.firstItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(view.safeAreaLayoutGuide))))
27+
assertThat(constraint?.firstItem, presentAnd(instanceOfAnd(equalTo(view))))
2828
assertThat(constraint?.secondAttribute, presentAnd(equalTo(.centerX)))
29-
assertThat(constraint?.secondItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(superview.safeAreaLayoutGuide))))
29+
assertThat(constraint?.secondItem, presentAnd(instanceOfAnd(equalTo(superview))))
3030
assertThat(constraint?.constant, presentAnd(equalTo(0)))
3131
assertThat(constraint?.isActive, presentAnd(equalTo(true)))
3232
assertThat(view.translatesAutoresizingMaskIntoConstraints, equalTo(false))
@@ -55,9 +55,9 @@ class PinLayout_Safe_Center: PinLayout_Base_Test {
5555
// then
5656
assertThat(constraint, present())
5757
assertThat(constraint?.firstAttribute, equalTo(.centerX))
58-
assertThat(constraint?.firstItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(view.safeAreaLayoutGuide))))
58+
assertThat(constraint?.firstItem, presentAnd(instanceOfAnd(equalTo(view))))
5959
assertThat(constraint?.secondAttribute, presentAnd(equalTo(.centerX)))
60-
assertThat(constraint?.secondItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(other.safeAreaLayoutGuide))))
60+
assertThat(constraint?.secondItem, presentAnd(instanceOfAnd(equalTo(other))))
6161
assertThat(constraint?.constant, presentAnd(equalTo(0)))
6262
assertThat(constraint?.isActive, presentAnd(equalTo(true)))
6363
assertThat(view.translatesAutoresizingMaskIntoConstraints, equalTo(false))
@@ -73,9 +73,9 @@ class PinLayout_Safe_Center: PinLayout_Base_Test {
7373
// then
7474
assertThat(constraint, present())
7575
assertThat(constraint?.firstAttribute, equalTo(.centerY))
76-
assertThat(constraint?.firstItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(view.safeAreaLayoutGuide))))
76+
assertThat(constraint?.firstItem, presentAnd(instanceOfAnd(equalTo(view))))
7777
assertThat(constraint?.secondAttribute, presentAnd(equalTo(.centerY)))
78-
assertThat(constraint?.secondItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(superview.safeAreaLayoutGuide))))
78+
assertThat(constraint?.secondItem, presentAnd(instanceOfAnd(equalTo(superview))))
7979
assertThat(constraint?.constant, presentAnd(equalTo(0)))
8080
assertThat(constraint?.isActive, presentAnd(equalTo(true)))
8181
assertThat(view.translatesAutoresizingMaskIntoConstraints, equalTo(false))
@@ -105,9 +105,9 @@ class PinLayout_Safe_Center: PinLayout_Base_Test {
105105
// then
106106
assertThat(constraint, present())
107107
assertThat(constraint?.firstAttribute, equalTo(.centerY))
108-
assertThat(constraint?.firstItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(view.safeAreaLayoutGuide))))
108+
assertThat(constraint?.firstItem, presentAnd(instanceOfAnd(equalTo(view))))
109109
assertThat(constraint?.secondAttribute, presentAnd(equalTo(.centerY)))
110-
assertThat(constraint?.secondItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(other.safeAreaLayoutGuide))))
110+
assertThat(constraint?.secondItem, presentAnd(instanceOfAnd(equalTo(other))))
111111
assertThat(constraint?.constant, presentAnd(equalTo(0)))
112112
assertThat(constraint?.isActive, presentAnd(equalTo(true)))
113113
assertThat(view.translatesAutoresizingMaskIntoConstraints, equalTo(false))
@@ -127,8 +127,8 @@ class PinLayout_Safe_Center: PinLayout_Base_Test {
127127
assertThat(constraints.first?.firstAttribute, equalTo(.centerX))
128128
assertThat(constraints.last?.firstAttribute, equalTo(.centerY))
129129

130-
assertThat(constraints.first?.secondItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(superview.safeAreaLayoutGuide))))
131-
assertThat(constraints.last?.secondItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(superview.safeAreaLayoutGuide))))
130+
assertThat(constraints.first?.secondItem, presentAnd(instanceOfAnd(equalTo(superview))))
131+
assertThat(constraints.last?.secondItem, presentAnd(instanceOfAnd(equalTo(superview))))
132132
}
133133

134134

@@ -145,8 +145,8 @@ class PinLayout_Safe_Center: PinLayout_Base_Test {
145145
assertThat(constraints.first?.firstAttribute, equalTo(.centerX))
146146
assertThat(constraints.last?.firstAttribute, equalTo(.centerY))
147147

148-
assertThat(constraints.first?.secondItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(other.safeAreaLayoutGuide))))
149-
assertThat(constraints.last?.secondItem, presentAnd(instanceOf(UILayoutGuide.self, and:equalTo(other.safeAreaLayoutGuide))))
148+
assertThat(constraints.first?.secondItem, presentAnd(instanceOfAnd(equalTo(other))))
149+
assertThat(constraints.last?.secondItem, presentAnd(instanceOfAnd(equalTo(other))))
150150
}
151151

152152

0 commit comments

Comments
 (0)