Skip to content

Commit

Permalink
add guard to Hero.shared methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lkzhao committed Jan 11, 2017
1 parent 1e99d3e commit 5c83f43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions Hero/Hero.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ public class Hero:NSObject {
public var container: UIView! {
return animatingViewContainer
}
public var transitioning:Bool{
return transitionContainer != nil
}
var transitionContainer:UIView!
public var presenting = true
public fileprivate(set) var presenting = true
fileprivate var completionCallback: (() -> Void)?

fileprivate var maxDurationNeeded: TimeInterval = 0.0
Expand Down Expand Up @@ -207,6 +210,7 @@ internal extension Hero {
}

internal func transition(from: UIViewController, to: UIViewController, in view: UIView, completion: (() -> Void)? = nil) {
guard !transitioning else { return }
inContainerController = false
presenting = true
transitionContainer = view
Expand All @@ -217,7 +221,7 @@ internal extension Hero {
}

internal func end(finished: Bool) {
guard transitionContainer != nil else { return }
guard transitioning else { return }
for animator in animators{
animator.clean()
}
Expand Down Expand Up @@ -269,16 +273,19 @@ internal extension Hero {
}
}

extension Hero {
public extension Hero {
public func update(progress: Double) {
let p = max(0, min(1, progress))
lastProgress = p
guard transitioning else { return }
for animator in animators {
animator.seekTo(timePassed: p * maxDurationNeeded)
}
transitionContext?.updateInteractiveTransition(CGFloat(p))
}

public func end() {
guard transitioning else { return }
var maxTime:TimeInterval = 0
for animator in animators {
maxTime = max(maxTime, animator.resume(timePassed:lastProgress*maxDurationNeeded, reverse: false))
Expand All @@ -288,7 +295,9 @@ extension Hero {
self.end(finished: true)
}
}

public func cancel() {
guard transitioning else { return }
var maxTime:TimeInterval = 0
for animator in animators {
maxTime = max(maxTime, animator.resume(timePassed:lastProgress*maxDurationNeeded, reverse: true))
Expand All @@ -300,6 +309,7 @@ extension Hero {
}

public func temporarilySet(view:UIView, modifiers:[HeroModifier]){
guard transitioning else { return }
let targetState = HeroTargetState(modifiers: modifiers)
if let otherView = context.pairedView(for: view){
for animator in animators {
Expand All @@ -314,9 +324,7 @@ extension Hero {

extension Hero: UIViewControllerAnimatedTransitioning {
public func animateTransition(using context: UIViewControllerContextTransitioning) {
if transitionContext != nil {
return
}
guard !transitioning else { return }
transitionContext = context
fromViewController = fromViewController ?? context.viewController(forKey: .from)
toViewController = toViewController ?? context.viewController(forKey: .to)
Expand Down
2 changes: 1 addition & 1 deletion Hero/HeroContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ extension HeroContext{
let snapShotView = UIView()
snapShotView.addSubview(contentView)
snapshot = snapShotView
} else if let barView = view as? UINavigationBar {
} else if let barView = view as? UINavigationBar, barView.isTranslucent {
let newBarView = UINavigationBar(frame: barView.frame)

newBarView.barStyle = barView.barStyle
Expand Down

0 comments on commit 5c83f43

Please sign in to comment.