Skip to content

Commit 4ec55df

Browse files
committed
Fix ReadableLayoutMargins
1 parent 8502ef7 commit 4ec55df

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

Tests/iOS/ReadableLayoutMarginsSpec.swift

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,8 @@ class ReadableLayoutMargins: QuickSpec {
8282
setupWindow(with: viewController)
8383

8484
aView.pin.all(rootView.pin.readableMargins)
85-
86-
#if os(iOS)
87-
expect(aView.frame).to(equal(CGRect(x: 8, y: 8, width: 384.0, height: 384.0)))
88-
#elseif os(tvOS)
89-
expect(aView.frame).to(equal(CGRect(x: 88, y: 68, width: 304.0, height: 324.0)))
90-
#else
91-
expect(aView.frame).to(equal(CGRect(x: 98, y: 68, width: 294.0, height: 324.0)))
92-
#endif
85+
86+
expect(aView.frame).to(equal(rootView.readableContentGuide.layoutFrame))
9387
}
9488
}
9589

@@ -98,27 +92,44 @@ class ReadableLayoutMargins: QuickSpec {
9892
setupWindow(with: viewController)
9993

10094
aView.pin.all(rootView.pin.layoutMargins)
101-
102-
#if os(iOS)
103-
expect(aView.frame).to(equal(CGRect(x: 8, y: 8, width: 384.0, height: 384.0)))
104-
#elseif os(tvOS)
105-
expect(aView.frame).to(equal(CGRect(x: 88, y: 68, width: 304.0, height: 324.0)))
106-
#else
107-
expect(aView.frame).to(equal(CGRect(x: 98, y: 68, width: 294.0, height: 324.0)))
108-
#endif
95+
96+
let layoutMargins = rootView.layoutMargins
97+
let aViewFrame = CGRect(
98+
x: layoutMargins.left,
99+
y: layoutMargins.top,
100+
width: rootView.frame.width - (layoutMargins.left + layoutMargins.right),
101+
height: rootView.frame.height - (layoutMargins.top + layoutMargins.bottom)
102+
)
103+
expect(aView.frame).to(equal(aViewFrame))
109104
}
110105
}
111106

112-
#if os(iOS) && compiler(>=5.5)
107+
#if os(iOS)
113108
describe("Using pin.keyboardArea") {
114109
it("test") {
115110
setupWindow(with: viewController)
116111

117112
rootView.pin.top(0).horizontally()
118-
rootView.pin.bottom(rootView.pin.keyboardArea.minY)
113+
rootView.pin.bottom(rootView.pin.keyboardArea.height)
114+
115+
let keyboardLayoutFrame: CGRect
116+
117+
if #available(iOS 15, *) {
118+
keyboardLayoutFrame = rootView.keyboardLayoutGuide.layoutFrame
119+
} else {
120+
keyboardLayoutFrame = .zero
121+
}
122+
123+
let screenSize = viewController.view.frame
124+
let expectedRootViewFrame = CGRect(
125+
x: .zero,
126+
y: .zero,
127+
width: screenSize.width,
128+
height: screenSize.height - keyboardLayoutFrame.height
129+
)
119130

120-
expect(rootView.frame).to(equal(CGRect(x: 0, y: 267, width: 375, height: 400)))
121-
expect(rootView.pin.keyboardArea).to(equal(CGRect(x: 0, y: 0, width: 0, height: 0)))
131+
expect(rootView.frame).to(equal(expectedRootViewFrame))
132+
expect(rootView.pin.keyboardArea).to(equal(keyboardLayoutFrame))
122133
}
123134
}
124135
#endif

0 commit comments

Comments
 (0)