@@ -32,11 +32,10 @@ class TransitionWithPresentationTests: XCTestCase {
32
32
33
33
func testPresentationControllerIsQueriedAndCompletesWithoutAnimation( ) {
34
34
let presentedViewController = UIViewController ( )
35
- presentedViewController. mdm_transitionController. transition =
36
- PresentationTransition ( presentationControllerType: TestingPresentationController . self)
35
+ presentedViewController. mdm_transitionController. transition = PresentationTransition ( )
37
36
38
37
let didComplete = expectation ( description: " Did complete " )
39
- window. rootViewController!. present ( presentedViewController, animated: true ) {
38
+ window. rootViewController!. present ( presentedViewController, animated: false ) {
40
39
didComplete. fulfill ( )
41
40
}
42
41
@@ -47,8 +46,7 @@ class TransitionWithPresentationTests: XCTestCase {
47
46
48
47
func testPresentationControllerIsQueriedAndCompletesWithAnimation( ) {
49
48
let presentedViewController = UIViewController ( )
50
- presentedViewController. mdm_transitionController. transition =
51
- PresentationTransition ( presentationControllerType: TransitionPresentationController . self)
49
+ presentedViewController. mdm_transitionController. transition = PresentationTransition ( )
52
50
53
51
let didComplete = expectation ( description: " Did complete " )
54
52
window. rootViewController!. present ( presentedViewController, animated: true ) {
@@ -57,27 +55,68 @@ class TransitionWithPresentationTests: XCTestCase {
57
55
58
56
waitForExpectations ( timeout: 0.5 )
59
57
60
- XCTAssert ( presentedViewController. presentationController is TransitionPresentationController )
58
+ XCTAssert ( presentedViewController. presentationController is TestingPresentationController )
59
+ }
60
+
61
+ func testPresentedFrameMatchesWindowFrame( ) {
62
+ let presentedViewController = UIViewController ( )
63
+ let transition = InstantCompletionTransition ( )
64
+ presentedViewController. transitionController. transition = transition
65
+
66
+ let didComplete = expectation ( description: " Did complete " )
67
+ window. frame = CGRect ( x: 0 , y: 0 , width: 300 , height: 200 )
68
+ window. rootViewController!. present ( presentedViewController, animated: true ) {
69
+ didComplete. fulfill ( )
70
+ }
71
+
72
+ waitForExpectations ( timeout: 0.1 )
73
+
74
+ XCTAssertEqual ( window. rootViewController!. presentedViewController, presentedViewController)
75
+ XCTAssertEqual ( window. rootViewController!. presentedViewController? . view. bounds, window. bounds)
76
+ }
77
+
78
+ func testPresentedFrameMatchesPresentationFrame( ) {
79
+ let presentedViewController = UIViewController ( )
80
+ let transition = PresentationTransition ( )
81
+ transition. presentationFrame = CGRect ( x: 100 , y: 30 , width: 50 , height: 70 )
82
+ presentedViewController. transitionController. transition = transition
83
+
84
+ let didComplete = expectation ( description: " Did complete " )
85
+ window. frame = CGRect ( x: 0 , y: 0 , width: 300 , height: 200 )
86
+ window. rootViewController!. present ( presentedViewController, animated: true ) {
87
+ didComplete. fulfill ( )
88
+ }
89
+
90
+ waitForExpectations ( timeout: 0.1 )
91
+
92
+ XCTAssertEqual ( window. rootViewController!. presentedViewController, presentedViewController)
93
+ XCTAssertEqual ( window. rootViewController!. presentedViewController? . view. frame,
94
+ transition. presentationFrame)
61
95
}
62
96
}
63
97
64
98
final class TestingPresentationController : UIPresentationController {
99
+ var presentationFrame : CGRect ?
100
+ override var frameOfPresentedViewInContainerView : CGRect {
101
+ if let presentationFrame = presentationFrame {
102
+ return presentationFrame
103
+ }
104
+ return super. frameOfPresentedViewInContainerView
105
+ }
65
106
}
66
107
67
108
final class PresentationTransition : NSObject , TransitionWithPresentation {
68
- let presentationControllerType : UIPresentationController . Type
69
- init ( presentationControllerType: UIPresentationController . Type ) {
70
- self . presentationControllerType = presentationControllerType
71
-
72
- super. init ( )
73
- }
109
+ var presentationFrame : CGRect ?
74
110
75
111
func defaultModalPresentationStyle( ) -> UIModalPresentationStyle {
76
112
return . custom
77
113
}
78
114
79
115
func presentationController( forPresented presented: UIViewController , presenting: UIViewController , source: UIViewController ? ) -> UIPresentationController ? {
80
- return presentationControllerType. init ( presentedViewController: presented, presenting: presenting)
116
+ let presentationController =
117
+ TestingPresentationController ( presentedViewController: presented, presenting: presenting)
118
+ presentationController. presentationFrame = presentationFrame
119
+ return presentationController
81
120
}
82
121
83
122
func start( with context: TransitionContext ) {
0 commit comments