Commit 19664a2f by Daniel Dahan

partial work completed for reworking Motion and MotionController

parent baf1bf57
...@@ -198,8 +198,8 @@ ...@@ -198,8 +198,8 @@
96AEB6691EE4610F009A3BE0 /* Debug Plugin */, 96AEB6691EE4610F009A3BE0 /* Debug Plugin */,
96AEB66D1EE4610F009A3BE0 /* Extensions */, 96AEB66D1EE4610F009A3BE0 /* Extensions */,
96AEB6771EE4610F009A3BE0 /* Motion.swift */, 96AEB6771EE4610F009A3BE0 /* Motion.swift */,
963150D41EE51C7A002B0D42 /* MotionAnimation.swift */,
96AEB6781EE4610F009A3BE0 /* MotionController.swift */, 96AEB6781EE4610F009A3BE0 /* MotionController.swift */,
963150D41EE51C7A002B0D42 /* MotionAnimation.swift */,
96AEB6791EE4610F009A3BE0 /* MotionContext.swift */, 96AEB6791EE4610F009A3BE0 /* MotionContext.swift */,
96AEB67A1EE4610F009A3BE0 /* MotionIndependentController.swift */, 96AEB67A1EE4610F009A3BE0 /* MotionIndependentController.swift */,
96AEB67B1EE4610F009A3BE0 /* MotionTransition.swift */, 96AEB67B1EE4610F009A3BE0 /* MotionTransition.swift */,
......
...@@ -410,6 +410,11 @@ extension MotionCoreAnimationViewContext { ...@@ -410,6 +410,11 @@ extension MotionCoreAnimationViewContext {
return values return values
} }
/**
Moves a layer's animation to a given elapsed time.
- Parameter layer: A CALayer.
- Parameter elapsedTime: A TimeInterval.
*/
fileprivate func seek(layer: CALayer, elapsedTime: TimeInterval) { fileprivate func seek(layer: CALayer, elapsedTime: TimeInterval) {
let timeOffset = elapsedTime - targetState.delay let timeOffset = elapsedTime - targetState.delay
for (key, anim) in layer.animations { for (key, anim) in layer.animations {
......
...@@ -38,13 +38,13 @@ public class MotionDebugPlugin: MotionPlugin { ...@@ -38,13 +38,13 @@ public class MotionDebugPlugin: MotionPlugin {
var updating = false var updating = false
override public func animate(fromViews: [UIView], toViews: [UIView]) -> TimeInterval { override public func animate(fromViews: [UIView], toViews: [UIView]) -> TimeInterval {
if Motion.shared.forceNotInteractive { return 0 } if Motion.shared.forceNonInteractive { return 0 }
var hasArc = false var hasArc = false
for v in context.fromViews + context.toViews where context[v]?.arc != nil && context[v]?.position != nil { for v in context.fromViews + context.toViews where context[v]?.arc != nil && context[v]?.position != nil {
hasArc = true hasArc = true
break break
} }
let debugView = MotionDebugView(initialProcess: Motion.shared.presenting ? 0.0 : 1.0, showCurveButton:hasArc, showOnTop:MotionDebugPlugin.showOnTop) let debugView = MotionDebugView(initialProcess: Motion.shared.isPresenting ? 0.0 : 1.0, showCurveButton:hasArc, showOnTop:MotionDebugPlugin.showOnTop)
debugView.frame = Motion.shared.container.bounds debugView.frame = Motion.shared.container.bounds
debugView.delegate = self debugView.delegate = self
UIApplication.shared.keyWindow!.addSubview(debugView) UIApplication.shared.keyWindow!.addSubview(debugView)
...@@ -81,7 +81,7 @@ public class MotionDebugPlugin: MotionPlugin { ...@@ -81,7 +81,7 @@ public class MotionDebugPlugin: MotionPlugin {
extension MotionDebugPlugin:MotionDebugViewDelegate { extension MotionDebugPlugin:MotionDebugViewDelegate {
public func onDone() { public func onDone() {
guard let debugView = debugView else { return } guard let debugView = debugView else { return }
let seekValue = Motion.shared.presenting ? debugView.progress : 1.0 - debugView.progress let seekValue = Motion.shared.isPresenting ? debugView.progress : 1.0 - debugView.progress
if seekValue > 0.5 { if seekValue > 0.5 {
Motion.shared.end() Motion.shared.end()
} else { } else {
...@@ -90,7 +90,7 @@ extension MotionDebugPlugin:MotionDebugViewDelegate { ...@@ -90,7 +90,7 @@ extension MotionDebugPlugin:MotionDebugViewDelegate {
} }
public func onProcessSliderChanged(progress: Float) { public func onProcessSliderChanged(progress: Float) {
let seekValue = Motion.shared.presenting ? progress : 1.0 - progress let seekValue = Motion.shared.isPresenting ? progress : 1.0 - progress
Motion.shared.update(progress: Double(seekValue)) Motion.shared.update(progress: Double(seekValue))
} }
......
...@@ -235,11 +235,11 @@ class DefaultAnimationPreprocessor: BasePreprocessor { ...@@ -235,11 +235,11 @@ class DefaultAnimationPreprocessor: BasePreprocessor {
override func process(fromViews: [UIView], toViews: [UIView]) { override func process(fromViews: [UIView], toViews: [UIView]) {
guard let motion = motion else { return } guard let motion = motion else { return }
var defaultAnimation = motion.defaultAnimation var defaultAnimation = motion.defaultAnimation
let inNavigationController = motion.inNavigationController let inNavigationController = motion.isNavigationController
let inTabBarController = motion.inTabBarController let inTabBarController = motion.isTabBarController
let toViewController = motion.toViewController let toViewController = motion.toViewController
let fromViewController = motion.fromViewController let fromViewController = motion.fromViewController
let presenting = motion.presenting let presenting = motion.isPresenting
let fromOverFullScreen = motion.fromOverFullScreen let fromOverFullScreen = motion.fromOverFullScreen
let toOverFullScreen = motion.toOverFullScreen let toOverFullScreen = motion.toOverFullScreen
let toView = motion.toView let toView = motion.toView
......
...@@ -312,6 +312,7 @@ extension UIViewController { ...@@ -312,6 +312,7 @@ extension UIViewController {
/** /**
Replace the current view controller with another view controller on the Replace the current view controller with another view controller on the
navigation/modal stack. navigation/modal stack.
- Parameter with next: A UIViewController.
*/ */
public func motion_replaceViewController(with next: UIViewController) { public func motion_replaceViewController(with next: UIViewController) {
guard !Motion.shared.isTransitioning else { guard !Motion.shared.isTransitioning else {
...@@ -328,7 +329,7 @@ extension UIViewController { ...@@ -328,7 +329,7 @@ extension UIViewController {
} }
if navigationController.isMotionEnabled { if navigationController.isMotionEnabled {
Motion.shared.forceNotInteractive = true Motion.shared.forceNonInteractive = true
} }
navigationController.setViewControllers(v, animated: true) navigationController.setViewControllers(v, animated: true)
......
...@@ -56,8 +56,8 @@ public class MotionContext { ...@@ -56,8 +56,8 @@ public class MotionContext {
if let motionIdentifier = view.motionIdentifier { if let motionIdentifier = view.motionIdentifier {
idMap[motionIdentifier] = view idMap[motionIdentifier] = view
} }
if let modifiers = view.motionTransitions { if let transitions = view.motionTransitions {
targetStates[view] = MotionTargetState(modifiers: modifiers) targetStates[view] = MotionTargetState(transitions: transitions)
} }
} }
} }
......
...@@ -195,9 +195,9 @@ public extension MotionController { ...@@ -195,9 +195,9 @@ public extension MotionController {
- modifiers: the modifiers to override - modifiers: the modifiers to override
- view: the view to override to - view: the view to override to
*/ */
public func apply(modifiers: [MotionTransition], to view: UIView) { public func apply(transitions: [MotionTransition], to view: UIView) {
guard isTransitioning else { return } guard isTransitioning else { return }
let targetState = MotionTargetState(modifiers: modifiers) let targetState = MotionTargetState(transitions: transitions)
if let otherView = self.context.pairedView(for: view) { if let otherView = self.context.pairedView(for: view) {
for animator in self.animators { for animator in self.animators {
animator.apply(state: targetState, to: otherView) animator.apply(state: targetState, to: otherView)
...@@ -272,6 +272,8 @@ internal extension MotionController { ...@@ -272,6 +272,8 @@ internal extension MotionController {
} }
} }
func processContext() { func processContext() {
guard isTransitioning else { fatalError() } guard isTransitioning else { fatalError() }
for processor in processors { for processor in processors {
......
...@@ -105,16 +105,16 @@ public struct MotionTargetState { ...@@ -105,16 +105,16 @@ public struct MotionTargetState {
public var forceAnimate: Bool = false public var forceAnimate: Bool = false
public var custom: [String:Any]? public var custom: [String:Any]?
init(modifiers: [MotionTransition]) { init(transitions: [MotionTransition]) {
append(contentsOf: modifiers) append(contentsOf: transitions)
} }
public mutating func append(_ modifier: MotionTransition) { public mutating func append(_ transition: MotionTransition) {
modifier.apply(&self) transition.apply(&self)
} }
public mutating func append(contentsOf modifiers: [MotionTransition]) { public mutating func append(contentsOf transitions: [MotionTransition]) {
for modifier in modifiers { for modifier in transitions {
modifier.apply(&self) modifier.apply(&self)
} }
} }
......
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