Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit e70c512

Browse files
author
Jeff Verkoeyen
committed
Add presentedView tests.
1 parent 7ba8ea2 commit e70c512

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/unit/TransitionWithPresentationTests.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,54 @@ class TransitionWithPresentationTests: XCTestCase {
9393
XCTAssertEqual(window.rootViewController!.presentedViewController?.view.frame,
9494
transition.presentationFrame)
9595
}
96+
97+
func testNoFramesModifiedWhenThereIsAPresentationView() {
98+
let presentedViewController = UIViewController()
99+
let transition = PresentationTransition()
100+
let presentationView = UIView()
101+
transition.presentationView = presentationView
102+
presentedViewController.transitionController.transition = transition
103+
104+
let didComplete = expectation(description: "Did complete")
105+
window.frame = CGRect(x: 0, y: 0, width: 300, height: 200)
106+
window.rootViewController!.present(presentedViewController, animated: true) {
107+
didComplete.fulfill()
108+
}
109+
110+
waitForExpectations(timeout: 0.1)
111+
112+
XCTAssertEqual(window.rootViewController!.presentedViewController, presentedViewController)
113+
XCTAssertEqual(presentationView.frame, .zero)
114+
XCTAssertEqual(presentedViewController.view.frame, UIScreen.main.bounds)
115+
}
96116
}
97117

98118
final class TestingPresentationController: UIPresentationController {
99119
var presentationFrame: CGRect?
120+
var presentationView: UIView?
100121
override var frameOfPresentedViewInContainerView: CGRect {
101122
if let presentationFrame = presentationFrame {
102123
return presentationFrame
103124
}
104125
return super.frameOfPresentedViewInContainerView
105126
}
127+
128+
override var presentedView: UIView? {
129+
return presentationView
130+
}
131+
132+
override func presentationTransitionWillBegin() {
133+
super.presentationTransitionWillBegin()
134+
135+
if let presentationView = presentationView {
136+
containerView?.addSubview(presentationView)
137+
}
138+
}
106139
}
107140

108141
final class PresentationTransition: NSObject, TransitionWithPresentation {
109142
var presentationFrame: CGRect?
143+
var presentationView: UIView?
110144

111145
func defaultModalPresentationStyle() -> UIModalPresentationStyle {
112146
return .custom
@@ -116,6 +150,7 @@ final class PresentationTransition: NSObject, TransitionWithPresentation {
116150
let presentationController =
117151
TestingPresentationController(presentedViewController: presented, presenting: presenting)
118152
presentationController.presentationFrame = presentationFrame
153+
presentationController.presentationView = presentationView
119154
return presentationController
120155
}
121156

0 commit comments

Comments
 (0)