Commit 19664a2f by Daniel Dahan

partial work completed for reworking Motion and MotionController

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