Skip to content

Commit a535e62

Browse files
committed
fix Match transition inside a nav controller
1 parent 50dd96a commit a535e62

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

Sources/Hero2/Base/Transition.swift

+11
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ open class Transition: NSObject {
4848
private var canAddBlocks: Bool = false
4949
private var dismissBlocks: [() -> Void] = []
5050
private var presentBlocks: [() -> Void] = []
51+
private var startBlocks: [() -> Void] = []
5152
private var completeBlocks: [(Bool) -> Void] = []
5253
private var prepareBlocks: [() -> Void] = []
5354
private var pausedAnimations: [UIView: [String: CAAnimation]] = [:]
@@ -122,6 +123,10 @@ open class Transition: NSObject {
122123
prepareBlocks.append(block)
123124
}
124125

126+
public func addStartBlock(_ block: @escaping () -> Void) {
127+
startBlocks.append(block)
128+
}
129+
125130
// MARK: - Subclass Overrides
126131
open func animate() {}
127132
}
@@ -277,6 +282,12 @@ extension Transition: UIViewControllerAnimatedTransitioning {
277282
}
278283

279284
animator.startAnimation()
285+
286+
for block in startBlocks {
287+
block()
288+
}
289+
startBlocks = []
290+
280291
if isInteractive {
281292
animator.pauseAnimation()
282293
}

Sources/Hero2/BuiltinTransitions/MatchModalTransition.swift

+9-7
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,17 @@ open class MatchModalTransition: Transition {
110110
sourceViewPlaceholder.removeFromSuperview()
111111
foregroundContainerView.removeFromSuperview()
112112
}
113+
addStartBlock {
114+
if self.isInteractive, self.isMatched {
115+
self.pauseForegroundView()
116+
}
117+
}
113118
}
114119

115-
open override func animateTransition(using context: UIViewControllerContextTransitioning) {
116-
super.animateTransition(using: context)
117-
if isInteractive, isMatched {
118-
let position = foregroundContainerView.layer.presentation()?.position ?? foregroundContainerView.layer.position
119-
pause(view: foregroundContainerView, animationForKey: "position")
120-
foregroundContainerView.layer.position = position
121-
}
120+
func pauseForegroundView() {
121+
let position = foregroundContainerView.layer.presentation()?.position ?? foregroundContainerView.layer.position
122+
self.pause(view: foregroundContainerView, animationForKey: "position")
123+
foregroundContainerView.layer.position = position
122124
}
123125

124126
open override func animationEnded(_ transitionCompleted: Bool) {

0 commit comments

Comments
 (0)