Commit d7a293b6 by Daniel Dahan

updated handling of optionals with guards and ifs rather than blocks

parent 02256789
...@@ -154,10 +154,14 @@ fileprivate extension MotionController { ...@@ -154,10 +154,14 @@ fileprivate extension MotionController {
/// Updates the animators. /// Updates the animators.
func updateAnimators() { func updateAnimators() {
guard let a = animators else {
return
}
let v = elapsedTime * totalDuration let v = elapsedTime * totalDuration
animators?.forEach { for x in a {
$0.seek(to: v) x.seek(to: v)
} }
} }
...@@ -246,8 +250,11 @@ public extension MotionController { ...@@ -246,8 +250,11 @@ public extension MotionController {
} }
var v: TimeInterval = 0 var v: TimeInterval = 0
animators?.forEach {
v = max(v, $0.resume(at: elapsedTime * totalDuration, isReversed: false)) if let a = animators {
for x in a {
v = max(v, x.resume(at: elapsedTime * totalDuration, isReversed: false))
}
} }
complete(after: v, isFinished: true) complete(after: v, isFinished: true)
...@@ -304,11 +311,15 @@ public extension MotionController { ...@@ -304,11 +311,15 @@ public extension MotionController {
return return
} }
guard let a = animators else {
return
}
let s = MotionTransitionState(transitions: transitions) let s = MotionTransitionState(transitions: transitions)
let v = context.transitionPairedView(for: view) ?? view let v = context.transitionPairedView(for: view) ?? view
animators?.forEach { for x in a {
$0.apply(state: s, to: v) x.apply(state: s, to: v)
} }
} }
} }
...@@ -362,15 +373,15 @@ internal extension MotionController { ...@@ -362,15 +373,15 @@ internal extension MotionController {
/// Executes the preprocessors' process function. /// Executes the preprocessors' process function.
func processContext() { func processContext() {
guard isTransitioning else { guard isTransitioning else {
fatalError() return
} }
preprocessors?.forEach { [weak self] in guard let p = preprocessors else {
guard let s = self else { return
return }
}
for x in p {
$0.process(fromViews: s.context.fromViews, toViews: s.context.toViews) x.process(fromViews: context.fromViews, toViews: context.toViews)
} }
} }
...@@ -380,20 +391,20 @@ internal extension MotionController { ...@@ -380,20 +391,20 @@ internal extension MotionController {
*/ */
func animate() { func animate() {
guard isTransitioning else { guard isTransitioning else {
fatalError() return
} }
transitionPairs?.forEach { [weak self] in guard let tp = transitionPairs else {
guard let s = self else { return
return }
}
for x in tp {
for view in $0.fromViews { for v in x.fromViews {
s.context.hide(view: view) context.hide(view: v)
} }
for view in $0.toViews { for v in x.toViews {
s.context.hide(view: view) context.hide(view: v)
} }
} }
...@@ -402,8 +413,6 @@ internal extension MotionController { ...@@ -402,8 +413,6 @@ internal extension MotionController {
if let a = animators, let tp = transitionPairs { if let a = animators, let tp = transitionPairs {
for (i, x) in a.enumerated() { for (i, x) in a.enumerated() {
let d = x.animate(fromViews: tp[i].0, toViews: tp[i].1) let d = x.animate(fromViews: tp[i].0, toViews: tp[i].1)
if d == .infinity { if d == .infinity {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment