Commit fdf4c631 by Daniel Dahan

updated Motion with states

parent 5a76e020
...@@ -93,6 +93,7 @@ internal class MotionAnimatorViewContext { ...@@ -93,6 +93,7 @@ internal class MotionAnimatorViewContext {
or not. or not.
- Returns: A TimeInterval. - Returns: A TimeInterval.
*/ */
@discardableResult
func resume(at elapsedTime: TimeInterval, isReversed: Bool) -> TimeInterval { func resume(at elapsedTime: TimeInterval, isReversed: Bool) -> TimeInterval {
return 0 return 0
} }
......
...@@ -33,7 +33,7 @@ class MotionCoreAnimator: MotionAnimator { ...@@ -33,7 +33,7 @@ class MotionCoreAnimator: MotionAnimator {
/// A reference to the MotionContext. /// A reference to the MotionContext.
public var context: MotionContext! { public var context: MotionContext! {
return motion?.context return motion.context
} }
func clean() {} func clean() {}
......
...@@ -220,9 +220,6 @@ public class Motion: NSObject, MotionProgressRunnerDelegate { ...@@ -220,9 +220,6 @@ public class Motion: NSObject, MotionProgressRunnerDelegate {
/// Whether or not we are presenting the destination view controller. /// Whether or not we are presenting the destination view controller.
public internal(set) var isPresenting = true public internal(set) var isPresenting = true
/// Indicates whether the transition is animating or not.
public internal(set) var isAnimating = false
/** /**
A view container used to hold all the animating views during a A view container used to hold all the animating views during a
transition. transition.
...@@ -530,6 +527,7 @@ public extension Motion { ...@@ -530,6 +527,7 @@ public extension Motion {
return return
} }
state = .notified
isPresenting = true isPresenting = true
transitionContainer = view transitionContainer = view
fromViewController = from fromViewController = from
...@@ -707,7 +705,7 @@ extension Motion: UIViewControllerAnimatedTransitioning { ...@@ -707,7 +705,7 @@ extension Motion: UIViewControllerAnimatedTransitioning {
} }
public func animationEnded(_ transitionCompleted: Bool) { public func animationEnded(_ transitionCompleted: Bool) {
isAnimating = !transitionCompleted state = .possible
} }
} }
...@@ -718,13 +716,24 @@ extension Motion: UIViewControllerTransitioningDelegate { ...@@ -718,13 +716,24 @@ extension Motion: UIViewControllerTransitioningDelegate {
} }
public func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { public func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
guard !isTransitioning else {
return nil
}
state = .notified
isPresenting = true isPresenting = true
fromViewController = fromViewController ?? presenting fromViewController = fromViewController ?? presenting
toViewController = toViewController ?? presented toViewController = toViewController ?? presented
return self return self
} }
public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
guard !isTransitioning else {
return nil
}
state = .notified
isPresenting = false isPresenting = false
fromViewController = fromViewController ?? dismissed fromViewController = fromViewController ?? dismissed
return self return self
...@@ -751,10 +760,16 @@ extension Motion: UIViewControllerInteractiveTransitioning { ...@@ -751,10 +760,16 @@ extension Motion: UIViewControllerInteractiveTransitioning {
extension Motion: UINavigationControllerDelegate { extension Motion: UINavigationControllerDelegate {
public func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { public func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
guard !isTransitioning else {
return nil
}
state = .notified
isPresenting = .push == operation isPresenting = .push == operation
fromViewController = fromViewController ?? fromVC fromViewController = fromViewController ?? fromVC
toViewController = toViewController ?? toVC toViewController = toViewController ?? toVC
isNavigationController = true isNavigationController = true
return self return self
} }
...@@ -765,7 +780,11 @@ extension Motion: UINavigationControllerDelegate { ...@@ -765,7 +780,11 @@ extension Motion: UINavigationControllerDelegate {
extension Motion: UITabBarControllerDelegate { extension Motion: UITabBarControllerDelegate {
public func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool { public func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
return !isAnimating if isTransitioning {
cancel(isAnimated: false)
}
return true
} }
public func tabBarController(_ tabBarController: UITabBarController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { public func tabBarController(_ tabBarController: UITabBarController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
...@@ -773,7 +792,11 @@ extension Motion: UITabBarControllerDelegate { ...@@ -773,7 +792,11 @@ extension Motion: UITabBarControllerDelegate {
} }
public func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { public func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
isAnimating = true guard !isTransitioning else {
return nil
}
state = .notified
let fromVCIndex = tabBarController.childViewControllers.index(of: fromVC)! let fromVCIndex = tabBarController.childViewControllers.index(of: fromVC)!
let toVCIndex = tabBarController.childViewControllers.index(of: toVC)! let toVCIndex = tabBarController.childViewControllers.index(of: toVC)!
......
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