Commit adc55d38 by Daniel Dahan

reworked the MotionViewControllerDelegate

parent 40cbb847
......@@ -39,7 +39,6 @@
96AEB6A31EE4610F009A3BE0 /* MotionPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEB67D1EE4610F009A3BE0 /* MotionPlugin.swift */; };
96AEB6A41EE4610F009A3BE0 /* MotionStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEB67E1EE4610F009A3BE0 /* MotionStringConvertible.swift */; };
96AEB6A51EE4610F009A3BE0 /* MotionTransitionState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEB67F1EE4610F009A3BE0 /* MotionTransitionState.swift */; };
96AEB6A61EE4610F009A3BE0 /* MotionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEB6801EE4610F009A3BE0 /* MotionViewController.swift */; };
96AEB6A71EE4610F009A3BE0 /* Lexer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEB6821EE4610F009A3BE0 /* Lexer.swift */; };
96AEB6A81EE4610F009A3BE0 /* Nodes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEB6831EE4610F009A3BE0 /* Nodes.swift */; };
96AEB6A91EE4610F009A3BE0 /* Parser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96AEB6841EE4610F009A3BE0 /* Parser.swift */; };
......@@ -84,7 +83,6 @@
96AEB67D1EE4610F009A3BE0 /* MotionPlugin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MotionPlugin.swift; sourceTree = "<group>"; };
96AEB67E1EE4610F009A3BE0 /* MotionStringConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MotionStringConvertible.swift; sourceTree = "<group>"; };
96AEB67F1EE4610F009A3BE0 /* MotionTransitionState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MotionTransitionState.swift; sourceTree = "<group>"; };
96AEB6801EE4610F009A3BE0 /* MotionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MotionViewController.swift; sourceTree = "<group>"; };
96AEB6821EE4610F009A3BE0 /* Lexer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Lexer.swift; sourceTree = "<group>"; };
96AEB6831EE4610F009A3BE0 /* Nodes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Nodes.swift; sourceTree = "<group>"; };
96AEB6841EE4610F009A3BE0 /* Parser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Parser.swift; sourceTree = "<group>"; };
......@@ -209,11 +207,10 @@
966A7F0A1EEC424000A2DAAC /* MotionCoordinateSpace.swift */,
96AEB67F1EE4610F009A3BE0 /* MotionTransitionState.swift */,
96AEB67B1EE4610F009A3BE0 /* MotionTransition.swift */,
96AEB67C1EE4610F009A3BE0 /* MotionTransition+MotionStringConvertible.swift */,
96E49A3F1EEA08F8006D5A93 /* MotionTransitionObserver.swift */,
96AEB67D1EE4610F009A3BE0 /* MotionPlugin.swift */,
96AEB67E1EE4610F009A3BE0 /* MotionStringConvertible.swift */,
96AEB6801EE4610F009A3BE0 /* MotionViewController.swift */,
96E49A3F1EEA08F8006D5A93 /* MotionTransitionObserver.swift */,
96AEB67C1EE4610F009A3BE0 /* MotionTransition+MotionStringConvertible.swift */,
96AEB6811EE4610F009A3BE0 /* Parser */,
96AEB6861EE4610F009A3BE0 /* Preprocessors */,
);
......@@ -315,7 +312,6 @@
96AEB6961EE4610F009A3BE0 /* Motion+CAMediaTimingFunction.swift in Sources */,
96AEB6941EE4610F009A3BE0 /* Motion+Array.swift in Sources */,
96AEB6951EE4610F009A3BE0 /* Motion+CALayer.swift in Sources */,
96AEB6A61EE4610F009A3BE0 /* MotionViewController.swift in Sources */,
96AEB68E1EE4610F009A3BE0 /* MotionCoreAnimationViewContext.swift in Sources */,
96AEB6921EE4610F009A3BE0 /* MotionDebugView.swift in Sources */,
96E49A401EEA08F8006D5A93 /* MotionTransitionObserver.swift in Sources */,
......
......@@ -28,6 +28,87 @@
import UIKit
@objc(MotionViewControllerDelegate)
public protocol MotionViewControllerDelegate {
/**
An optional delegation method that is executed motion will start the transition.
- Parameter motion: A Motion instance.
- Parameter willStartTransitionFrom viewController: A UIViewController.
*/
@objc
optional func motionWillStartTransition(motion: Motion)
/**
An optional delegation method that is executed motion did end the transition.
- Parameter motion: A Motion instance.
- Parameter willStartTransitionFrom viewController: A UIViewController.
*/
@objc
optional func motionDidEndTransition(motion: Motion)
/**
An optional delegation method that is executed motion did cancel the transition.
- Parameter motion: A Motion instance.
- Parameter willStartTransitionFrom viewController: A UIViewController.
*/
@objc
optional func motionDidCancelTransition(motion: Motion)
/**
An optional delegation method that is executed when the source
view controller will start the transition.
- Parameter motion: A Motion instance.
- Parameter willStartTransitionFrom viewController: A UIViewController.
*/
@objc
optional func motion(motion: Motion, willStartTransitionFrom viewController: UIViewController)
/**
An optional delegation method that is executed when the source
view controller did end the transition.
- Parameter motion: A Motion instance.
- Parameter willStartTransitionFrom viewController: A UIViewController.
*/
@objc
optional func motion(motion: Motion, didEndTransitionFrom viewController: UIViewController)
/**
An optional delegation method that is executed when the source
view controller did cancel the transition.
- Parameter motion: A Motion instance.
- Parameter willStartTransitionFrom viewController: A UIViewController.
*/
@objc
optional func motion(motion: Motion, didCancelTransitionFrom viewController: UIViewController)
/**
An optional delegation method that is executed when the destination
view controller will start the transition.
- Parameter motion: A Motion instance.
- Parameter willStartTransitionFrom viewController: A UIViewController.
*/
@objc
optional func motion(motion: Motion, willStartTransitionTo viewController: UIViewController)
/**
An optional delegation method that is executed when the destination
view controller did end the transition.
- Parameter motion: A Motion instance.
- Parameter willStartTransitionFrom viewController: A UIViewController.
*/
@objc
optional func motion(motion: Motion, didEndTransitionTo viewController: UIViewController)
/**
An optional delegation method that is executed when the destination
view controller did cancel the transition.
- Parameter motion: A Motion instance.
- Parameter willStartTransitionFrom viewController: A UIViewController.
*/
@objc
optional func motion(motion: Motion, didCancelTransitionTo viewController: UIViewController)
}
/**
### The singleton class/object for controlling interactive transitions.
......@@ -253,28 +334,44 @@ internal extension Motion {
if finished {
if let fvc = fvc, let tvc = tvc {
processForMotionDelegate(viewController: fvc) {
$0.motionDidEndAnimatingTo?(viewController: tvc)
$0.motionDidEndTransition?()
processForMotionDelegate(viewController: fvc) { [weak self] in
guard let s = self else {
return
}
$0.motion?(motion: s, didEndTransitionTo: tvc)
$0.motionDidEndTransition?(motion: s)
}
processForMotionDelegate(viewController: tvc) {
$0.motionDidEndAnimatingFrom?(viewController: fvc)
$0.motionDidEndTransition?()
processForMotionDelegate(viewController: tvc) { [weak self] in
guard let s = self else {
return
}
$0.motion?(motion: s, didEndTransitionFrom: fvc)
$0.motionDidEndTransition?(motion: s)
}
}
tContext?.finishInteractiveTransition()
} else {
if let fvc = fvc, let tvc = tvc {
processForMotionDelegate(viewController: fvc) {
$0.motionDidCancelAnimatingTo?(viewController: tvc)
$0.motionDidCancelTransition?()
processForMotionDelegate(viewController: fvc) { [weak self] in
guard let s = self else {
return
}
$0.motion?(motion: s, didCancelTransitionTo: tvc)
$0.motionDidCancelTransition?(motion: s)
}
processForMotionDelegate(viewController: tvc) {
$0.motionDidCancelAnimatingFrom?(viewController: fvc)
$0.motionDidCancelTransition?()
processForMotionDelegate(viewController: tvc) { [weak self] in
guard let s = self else {
return
}
$0.motion?(motion: s, didCancelTransitionFrom: fvc)
$0.motionDidCancelTransition?(motion: s)
}
}
......@@ -292,14 +389,22 @@ fileprivate extension Motion {
return
}
processForMotionDelegate(viewController: fvc) {
$0.motionWillStartTransition?()
$0.motionWillStartAnimatingTo?(viewController: tvc)
processForMotionDelegate(viewController: fvc) { [weak self] in
guard let s = self else {
return
}
$0.motionWillStartTransition?(motion: s)
$0.motion?(motion: s, willStartTransitionTo: tvc)
}
processForMotionDelegate(viewController: tvc) {
$0.motionWillStartTransition?()
$0.motionWillStartAnimatingFrom?(viewController: fvc)
processForMotionDelegate(viewController: tvc) { [weak self] in
guard let s = self else {
return
}
$0.motionWillStartTransition?(motion: s)
$0.motion?(motion: s, willStartTransitionFrom: fvc)
}
}
......
/*
* The MIT License (MIT)
*
* Copyright (C) 2017, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved.
*
* Original Inspiration & Author
* Copyright (c) 2016 Luke Zhao <me@lkzhao.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import UIKit
@objc(MotionViewControllerDelegate)
public protocol MotionViewControllerDelegate {
@objc
optional func motionWillStartAnimatingFrom(viewController: UIViewController)
@objc
optional func motionDidEndAnimatingFrom(viewController: UIViewController)
@objc
optional func motionDidCancelAnimatingFrom(viewController: UIViewController)
@objc
optional func motionWillStartTransition()
@objc
optional func motionDidEndTransition()
@objc
optional func motionDidCancelTransition()
@objc
optional func motionWillStartAnimatingTo(viewController: UIViewController)
@objc
optional func motionDidEndAnimatingTo(viewController: UIViewController)
@objc
optional func motionDidCancelAnimatingTo(viewController: UIViewController)
}
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