@@ -9,87 +9,17 @@ import UIKit
9
9
10
10
/// A custom transition class.
11
11
/// Provides functionality for handling custom view controller transitions.
12
- open class CustomTransition : NSObject , ICoreTransition {
12
+ open class CustomTransition : CoreTransition {
13
13
// MARK: Properties
14
14
15
- /// The duration of the transition animation, measured in seconds.
16
- public let animationDuration : TimeInterval
17
-
18
- /// A flag indicating whether the transition is for presenting (`true`) or dismissing (`false`) a view controller.
19
- public private( set) var isPresenting = false
20
-
21
- /// The view controller that is presenting the view controller in the presented parameter.
22
- public private( set) weak var presentingViewController : UIViewController ?
23
- /// The view controller object that is about to be presented onscreen.
24
- public private( set) weak var presentedViewController : UIViewController ?
25
-
26
- /// The context object containing information about the transition.
27
- public private( set) weak var transitionContext : UIViewControllerContextTransitioning ?
28
- /// This is the target view controller that will be presented after the transition.
29
- public private( set) weak var toViewController : UIViewController ?
30
- /// This is the currently visible view controller before the transition begins.
31
- public private( set) weak var fromViewController : UIViewController ?
32
- /// Determine if the transition is interactive.
33
- public private( set) var isInteractive = false
34
-
35
- /// The source view controller.
36
- weak var owningController : UIViewController ?
37
-
38
- /// The container view serves as the parent view that holds both the from-view and to-view during the transition.
39
- public private( set) weak var transitionContainerView : UIView ?
40
-
41
- /// An object that drives an interactive animation between one view controller and another.
42
- private var interactionController : UIPercentDrivenInteractiveTransition ?
43
-
44
15
/// This represents the view's transformation state before the transition begins.
45
16
public private( set) var intitialTransform : CGAffineTransform ?
46
17
/// This represents the view's transformation state after the transition is completed.
47
18
public private( set) var finalTransform : CGAffineTransform ?
48
19
49
- // MARK: Initialization
50
-
51
- /// Initializes a new instance of the `CustomTransition` class.
52
- ///
53
- /// - Parameter animationDuration: The duration of the transition animation, measured in seconds.
54
- public init ( animationDuration: TimeInterval ) {
55
- self . animationDuration = animationDuration
56
- }
57
-
58
- // MARK: ICoreTransition
59
-
60
- open func performTransition( ) { }
61
-
62
- open func performDismissTransition( ) { }
63
-
64
- // MARK: Public
20
+ // MARK: Internal
65
21
66
- open func prepareForTransition( interactive _: Bool ) { }
67
-
68
- /// Completes the current transition and cleans up the transition state.
69
- ///
70
- /// - Parameter completion: An optional closure called with a Boolean value
71
- /// indicating whether the transition was successful (`true`) or cancelled (`false`).
72
- @MainActor
73
- open func completeTransaction( completion: ( ( Bool ) -> Void ) ? = nil ) {
74
- guard let transitionContext else {
75
- completion ? ( false )
76
- return
77
- }
78
-
79
- let isFinished = !transitionContext. transitionWasCancelled
80
-
81
- completion ? ( isFinished)
82
-
83
- transitionContext. completeTransition ( isFinished)
84
-
85
- self . transitionContext = nil
86
- presentedViewController = nil
87
- presentingViewController = nil
88
- }
89
-
90
- // MARK: Private
91
-
92
- private func prepareTransitionParameters( ) {
22
+ override func prepareTransitionParameters( ) {
93
23
guard let toViewController,
94
24
let fromViewController,
95
25
let transitionContext,
@@ -119,76 +49,3 @@ open class CustomTransition: NSObject, ICoreTransition {
119
49
}
120
50
}
121
51
}
122
-
123
- // MARK: IInteractiveTransition
124
-
125
- extension CustomTransition : IInteractiveTransition {
126
- public func beginInteractiveDismissalTransition( ) {
127
- interactionController = UIPercentDrivenInteractiveTransition ( )
128
- owningController? . dismiss ( animated: true )
129
- }
130
-
131
- public func updateInteractiveTransitionToProgress( progress: CGFloat ) {
132
- interactionController? . update ( progress)
133
- }
134
-
135
- public func cancelInteractiveTransition( ) {
136
- interactionController? . completionSpeed = 0.999
137
- interactionController? . cancel ( )
138
-
139
- interactionController = nil
140
- }
141
-
142
- public func finishInteractiveTransition( ) {
143
- interactionController? . finish ( )
144
- interactionController = nil
145
- }
146
- }
147
-
148
- // MARK: UIViewControllerAnimatedTransitioning
149
-
150
- extension CustomTransition : UIViewControllerAnimatedTransitioning {
151
- open func transitionDuration( using _: ( any UIViewControllerContextTransitioning ) ? ) -> TimeInterval {
152
- animationDuration
153
- }
154
-
155
- open func animateTransition( using transitionContext: any UIViewControllerContextTransitioning ) {
156
- self . transitionContext = transitionContext
157
- fromViewController = transitionContext. viewController ( forKey: . from)
158
- toViewController = transitionContext. viewController ( forKey: . to)
159
- isInteractive = transitionContext. isInteractive
160
- transitionContainerView = transitionContext. containerView
161
-
162
- prepareTransitionParameters ( )
163
-
164
- prepareForTransition ( interactive: isInteractive)
165
-
166
- if isPresenting {
167
- performTransition ( )
168
- } else {
169
- performDismissTransition ( )
170
- }
171
- }
172
- }
173
-
174
- // MARK: UIViewControllerTransitioningDelegate
175
-
176
- extension CustomTransition : UIViewControllerTransitioningDelegate {
177
- public func animationController(
178
- forPresented presented: UIViewController ,
179
- presenting: UIViewController ,
180
- source _: UIViewController
181
- ) -> ( any UIViewControllerAnimatedTransitioning ) ? {
182
- presentingViewController = presenting
183
- presentedViewController = presented
184
- isPresenting = true
185
- return self
186
- }
187
-
188
- public func animationController( forDismissed dismissed: UIViewController ) -> UIViewControllerAnimatedTransitioning ? {
189
- presentingViewController = dismissed
190
- presentedViewController = dismissed. presentingViewController
191
- isPresenting = false
192
- return self
193
- }
194
- }
0 commit comments