Skip to content

Commit

Permalink
Merge pull request #736 from HeroTransitions/feature/735_HeroViewProp…
Browse files Browse the repository at this point in the history
…ertyViewContext_Crash

Fixes #735 check 0 divide, use TimeInt.zero over 0
  • Loading branch information
JoeMatt authored May 6, 2022
2 parents 9f8fe2b + a260a48 commit f9f018d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
3 changes: 2 additions & 1 deletion Sources/Animator/HeroViewPropertyViewContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ internal class HeroViewPropertyViewContext: HeroAnimatorViewContext {
}

override func resume(timePassed: TimeInterval, reverse: Bool) -> TimeInterval {
guard let visualEffectView = snapshot as? UIVisualEffectView else { return 0 }
guard let visualEffectView = snapshot as? UIVisualEffectView else { return .zero }
guard duration > 0 else { return .zero }
if reverse {
viewPropertyAnimator?.stopAnimation(false)
viewPropertyAnimator?.finishAnimation(at: .current)
Expand Down
36 changes: 14 additions & 22 deletions Sources/Transition/HeroTransition+Start.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ extension HeroTransition {
}

// There is no covariant in Swift, so we need to add plugins one by one.
for plugin in plugins {
processors.append(plugin)
animators.append(plugin)
plugins.forEach {
processors.append($0)
animators.append($0)
}

transitionContainer?.isUserInteractionEnabled = isUserInteractionEnabled
Expand All @@ -110,14 +110,14 @@ extension HeroTransition {

context = HeroContext(container: container)

for processor in processors {
processor.hero = self
processors.forEach {
$0.hero = self
}
for animator in animators {
animator.hero = self
animators.forEach {
$0.hero = self
}

if let toView = toView, let fromView = fromView {
if let toView = toView, let fromView = fromView, toView != fromView {
// if we're presenting a view controller, remember the position & dimension
// of the view relative to the transition container so that we can:
// - correctly place the view in the transition container when presenting
Expand Down Expand Up @@ -160,24 +160,16 @@ extension HeroTransition {
context.insertToViewFirst = true
}

for processor in processors {
processor.process(fromViews: context.fromViews, toViews: context.toViews)
processors.forEach {
$0.process(fromViews: context.fromViews, toViews: context.toViews)
}

animatingFromViews = context.fromViews.filter { (view: UIView) -> Bool in
for animator in animators {
if animator.canAnimate(view: view, appearing: false) {
return true
}
}
return false
animators.contains { $0.canAnimate(view: view, appearing: false) }
}

animatingToViews = context.toViews.filter { (view: UIView) -> Bool in
for animator in animators {
if animator.canAnimate(view: view, appearing: true) {
return true
}
}
return false
animators.contains { $0.canAnimate(view: view, appearing: true) }
}

if let toView = toView {
Expand Down

0 comments on commit f9f018d

Please sign in to comment.