@@ -13,6 +13,8 @@ open class TransitionViewController: _fluid_WrapperViewController {
1313 private var state : State = . init( )
1414
1515 public var transition : TransitionPair
16+ private var addingTransitionContext : AddingTransitionContext ?
17+ private var removingTransitionContext : RemovingTransitionContext ?
1618
1719 public init (
1820 bodyViewController: UIViewController ,
@@ -77,6 +79,9 @@ open class TransitionViewController: _fluid_WrapperViewController {
7779
7880 state. countViewDidAppear += 1
7981
82+ /**
83+ For standalone usage
84+ */
8085 if state. countViewDidAppear == 1 {
8186
8287 self . view. alpha = 1
@@ -87,20 +92,35 @@ open class TransitionViewController: _fluid_WrapperViewController {
8792 let presentationController = presentationController
8893 {
8994
95+ removingTransitionContext? . invalidate ( )
96+ removingTransitionContext = nil
97+
9098 let addingTransition = transition. adding ?? . noAnimation
9199
92100 /// presenting as presentation
93101 /// super.viewDidAppear(animated)
94102
95- addingTransition. startTransition (
96- context: . init(
97- contentView: presentationController. containerView!,
98- fromViewController: presentingViewController,
99- toViewController: self ,
100- onCompleted: { _ in
101103
104+ let context = AddingTransitionContext . init (
105+ contentView: presentationController. containerView!,
106+ fromViewController: presentingViewController,
107+ toViewController: self ,
108+ onCompleted: { context in
109+
110+ self . addingTransitionContext = nil
111+
112+ guard context. isInvalidated == false else {
113+ return
102114 }
103- )
115+
116+ context. transitionFinished ( )
117+ }
118+ )
119+
120+ self . addingTransitionContext = context
121+
122+ addingTransition. startTransition (
123+ context: context
104124 )
105125
106126 }
@@ -118,18 +138,30 @@ open class TransitionViewController: _fluid_WrapperViewController {
118138 preconditionFailure ( )
119139 }
120140
121- return . init(
141+ addingTransitionContext? . invalidate ( )
142+ addingTransitionContext = nil
143+
144+ let context = RemovingTransitionContext . init (
122145 contentView: presentationController. containerView!,
123146 fromViewController: self ,
124147 toViewController: presentingViewController,
125148 onCompleted: { [ weak self] context in
126149
127150 guard let self = self else { return }
128151
152+ guard context. isInvalidated == false else { return }
153+
154+ context. transitionFinished ( )
155+ self . removingTransitionContext = nil
156+
129157 self . dismiss ( animated: false , completion: nil )
130158
131159 } )
132160
161+ removingTransitionContext = context
162+
163+ return context
164+
133165 }
134166
135167 public func remove( ) {
@@ -142,6 +174,9 @@ open class TransitionViewController: _fluid_WrapperViewController {
142174 return
143175 }
144176
177+ addingTransitionContext? . invalidate ( )
178+ addingTransitionContext = nil
179+
145180 let context = RemovingTransitionContext . init (
146181 contentView: presentationController. containerView!,
147182 fromViewController: self ,
@@ -150,10 +185,17 @@ open class TransitionViewController: _fluid_WrapperViewController {
150185
151186 guard let self = self else { return }
152187
188+ guard context. isInvalidated == false else { return }
189+
190+ context. transitionFinished ( )
191+ self . removingTransitionContext = nil
192+
153193 self . dismiss ( animated: false , completion: nil )
154194
155195 } )
156196
197+ removingTransitionContext = context
198+
157199 let transition = transition. removing ?? . noAnimation
158200
159201 transition. startTransition ( context: context)
0 commit comments