Commit aa31695e by Daniel Dahan

finished MotionController and Motion rework

parent 3e422773
...@@ -347,6 +347,7 @@ internal extension MotionController { ...@@ -347,6 +347,7 @@ internal extension MotionController {
} }
internal extension MotionController { internal extension MotionController {
/// Executes the preprocessors' process function.
func processContext() { func processContext() {
guard isTransitioning else { guard isTransitioning else {
fatalError() fatalError()
...@@ -357,45 +358,53 @@ internal extension MotionController { ...@@ -357,45 +358,53 @@ internal extension MotionController {
} }
} }
/// Actually animate the views /**
/// subclass should call `prepareTransition` & `prepareTransitionPairs` before calling `animate` Animates the views. Subclasses should call `prepareTransition` &
`prepareTransitionPairs` before calling `animate`.
*/
func animate() { func animate() {
guard isTransitioning else { guard isTransitioning else {
fatalError() fatalError()
} }
for (currentFromViews, currentToViews) in transitionPairs { for (fv, tv) in transitionPairs {
// auto hide all animated views for view in fv {
for view in currentFromViews {
context.hide(view: view) context.hide(view: view)
} }
for view in currentToViews { for view in tv {
context.hide(view: view) context.hide(view: view)
} }
} }
var totalDuration: TimeInterval = 0 var t: TimeInterval = 0
var animatorWantsInteractive = false var v = false
for (i, animator) in animators.enumerated() { for (i, a) in animators.enumerated() {
let duration = animator.animate(fromViews: transitionPairs[i].0, toViews: transitionPairs[i].1) let d = a.animate(fromViews: transitionPairs[i].0, toViews: transitionPairs[i].1)
if duration == .infinity { if d == .infinity {
animatorWantsInteractive = true v = true
} else { } else {
totalDuration = max(totalDuration, duration) t = max(t, d)
} }
} }
self.totalDuration = totalDuration totalDuration = t
if animatorWantsInteractive {
if v {
update(elapsedTime: 0) update(elapsedTime: 0)
} else { } else {
complete(after: totalDuration, isFinished: true) complete(after: t, isFinished: true)
} }
} }
/**
Complete the transition.
- Parameter after: A TimeInterval.
- Parameter isFinished: A Boolean indicating if the transition
has completed.
*/
func complete(after: TimeInterval, isFinished: Bool) { func complete(after: TimeInterval, isFinished: Bool) {
guard isTransitioning else { guard isTransitioning else {
fatalError() fatalError()
...@@ -412,16 +421,21 @@ internal extension MotionController { ...@@ -412,16 +421,21 @@ internal extension MotionController {
self.beginTime = CACurrentMediaTime() - v self.beginTime = CACurrentMediaTime() - v
} }
/**
Complete the transition.
- Parameter isFinished: A Boolean indicating if the transition
has completed.
*/
func complete(isFinished: Bool) { func complete(isFinished: Bool) {
guard isTransitioning else { guard isTransitioning else {
fatalError() fatalError()
} }
for animator in animators { for a in animators {
animator.clean() a.clean()
} }
transitionContainer!.isUserInteractionEnabled = true transitionContainer?.isUserInteractionEnabled = true
let completion = completionCallback let completion = completionCallback
......
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