Commit 83ab6b00 by Daniel Dahan

UIViewController.motionModalTransitionType renamed to UIViewController.motionTransitionType

parent b9a25764
## 1.2.5
* `UIViewController.motionModalTransitionType` renamed to `UIViewController.motionTransitionType`.
## 1.2.4 ## 1.2.4
* Added begin / end transition methods for from / to view controllers. * Added begin / end transition methods for from / to view controllers.
......
...@@ -33,24 +33,24 @@ fileprivate var AssociatedInstanceKey: UInt8 = 0 ...@@ -33,24 +33,24 @@ fileprivate var AssociatedInstanceKey: UInt8 = 0
fileprivate struct AssociatedInstance { fileprivate struct AssociatedInstance {
/// A reference to the modal animation. /// A reference to the modal animation.
var modalTransitionType: MotionTransitionType var modalTransitionType: MotionTransitionType
/// A reference to the navigation animation. /// A reference to the navigation animation.
var navigationTransitionType: MotionTransitionType var navigationTransitionType: MotionTransitionType
/// A reference to the tabBar animation. /// A reference to the tabBar animation.
var tabBarTransitionType: MotionTransitionType var tabBarTransitionType: MotionTransitionType
/// A reference to the stored snapshot. /// A reference to the stored snapshot.
var storedSnapshot: UIView? var storedSnapshot: UIView?
/** /**
A reference to the previous navigation controller delegate A reference to the previous navigation controller delegate
before Motion was enabled. before Motion was enabled.
*/ */
weak var previousNavigationDelegate: UINavigationControllerDelegate? weak var previousNavigationDelegate: UINavigationControllerDelegate?
/** /**
A reference to the previous tab bar controller delegate A reference to the previous tab bar controller delegate
before Motion was enabled. before Motion was enabled.
*/ */
weak var previousTabBarDelegate: UITabBarControllerDelegate? weak var previousTabBarDelegate: UITabBarControllerDelegate?
...@@ -73,9 +73,9 @@ extension UIViewController { ...@@ -73,9 +73,9 @@ extension UIViewController {
AssociatedObject.set(base: self, key: &AssociatedInstanceKey, value: value) AssociatedObject.set(base: self, key: &AssociatedInstanceKey, value: value)
} }
} }
/// default motion animation type for presenting & dismissing modally /// Default motion animation type for presenting & dismissing modally.
public var motionModalTransitionType: MotionTransitionType { public var motionTransitionType: MotionTransitionType {
get { get {
return associatedInstance.modalTransitionType return associatedInstance.modalTransitionType
} }
...@@ -83,8 +83,8 @@ extension UIViewController { ...@@ -83,8 +83,8 @@ extension UIViewController {
associatedInstance.modalTransitionType = value associatedInstance.modalTransitionType = value
} }
} }
/// used for .overFullScreen presentation /// Used for .overFullScreen presentation.
internal var motionStoredSnapshot: UIView? { internal var motionStoredSnapshot: UIView? {
get { get {
return associatedInstance.storedSnapshot return associatedInstance.storedSnapshot
...@@ -93,7 +93,7 @@ extension UIViewController { ...@@ -93,7 +93,7 @@ extension UIViewController {
associatedInstance.storedSnapshot = value associatedInstance.storedSnapshot = value
} }
} }
/** /**
A reference to the previous navigation controller delegate A reference to the previous navigation controller delegate
before Motion was enabled. before Motion was enabled.
...@@ -184,8 +184,8 @@ extension UITabBarController { ...@@ -184,8 +184,8 @@ extension UITabBarController {
extension UIViewController { extension UIViewController {
/** /**
Dismiss the current view controller with animation. Will perform a Dismiss the current view controller with animation. Will perform a
navigationController.popViewController if the current view controller navigationController.popViewController if the current view controller
is contained inside a navigationController is contained inside a navigationController
*/ */
@IBAction @IBAction
...@@ -196,33 +196,41 @@ extension UIViewController { ...@@ -196,33 +196,41 @@ extension UIViewController {
dismiss(animated: true) dismiss(animated: true)
} }
} }
/// Unwind to the root view controller using Motion. /// Unwind to the root view controller using Motion.
@IBAction @IBAction
public func motionUnwindToRootViewController() { public func motionUnwindToRootViewController() {
motionUnwindToViewController { $0.presentingViewController == nil } motionUnwindToViewController {
nil == $0.presentingViewController
}
} }
/// Unwind to a specific view controller using Motion. /// Unwind to a specific view controller using Motion.
public func motionUnwindToViewController(_ toViewController: UIViewController) { public func motionUnwindToViewController(_ toViewController: UIViewController) {
motionUnwindToViewController { $0 == toViewController } motionUnwindToViewController {
$0 == toViewController
}
} }
/// Unwind to a view controller that responds to the given selector using Motion. /// Unwind to a view controller that responds to the given selector using Motion.
public func motionUnwindToViewController(withSelector: Selector) { public func motionUnwindToViewController(withSelector: Selector) {
motionUnwindToViewController { $0.responds(to: withSelector) } motionUnwindToViewController {
$0.responds(to: withSelector)
}
} }
/// Unwind to a view controller with given class using Motion /// Unwind to a view controller with given class using Motion
public func motionUnwindToViewController(withClass: AnyClass) { public func motionUnwindToViewController(withClass: AnyClass) {
motionUnwindToViewController { $0.isKind(of: withClass) } motionUnwindToViewController {
$0.isKind(of: withClass)
}
} }
/// Unwind to a view controller that the matchBlock returns true on. /// Unwind to a view controller that the matchBlock returns true on.
public func motionUnwindToViewController(withMatchBlock: (UIViewController) -> Bool) { public func motionUnwindToViewController(withMatchBlock: (UIViewController) -> Bool) {
var target: UIViewController? var target: UIViewController?
var current: UIViewController? = self var current: UIViewController? = self
while nil == target && nil != current { while nil == target && nil != current {
if let childViewControllers = (current as? UINavigationController)?.childViewControllers ?? current!.navigationController?.childViewControllers { if let childViewControllers = (current as? UINavigationController)?.childViewControllers ?? current!.navigationController?.childViewControllers {
for v in childViewControllers.reversed() { for v in childViewControllers.reversed() {
...@@ -232,34 +240,34 @@ extension UIViewController { ...@@ -232,34 +240,34 @@ extension UIViewController {
} }
} }
} }
guard nil == target else { guard nil == target else {
continue continue
} }
current = current?.presentingViewController current = current?.presentingViewController
guard let v = current, withMatchBlock(v) else { guard let v = current, withMatchBlock(v) else {
continue continue
} }
target = v target = v
} }
guard let v = target else { guard let v = target else {
return return
} }
guard nil != v.presentedViewController else { guard nil != v.presentedViewController else {
v.navigationController?.popToViewController(v, animated: true) v.navigationController?.popToViewController(v, animated: true)
return return
} }
v.navigationController?.popToViewController(v, animated: false) v.navigationController?.popToViewController(v, animated: false)
let fromVC = navigationController ?? self let fromVC = navigationController ?? self
let toVC = v.navigationController ?? v let toVC = v.navigationController ?? v
if v.presentedViewController != fromVC { if v.presentedViewController != fromVC {
/** /**
UIKit's UIViewController.dismiss will jump to target.presentedViewController then perform the dismiss. UIKit's UIViewController.dismiss will jump to target.presentedViewController then perform the dismiss.
...@@ -267,17 +275,17 @@ extension UIViewController { ...@@ -267,17 +275,17 @@ extension UIViewController {
And also force Motion to use the current view controller as the fromViewController. And also force Motion to use the current view controller as the fromViewController.
*/ */
Motion.shared.fromViewController = fromVC Motion.shared.fromViewController = fromVC
guard let snapshot = fromVC.view.snapshotView(afterScreenUpdates: true) else { guard let snapshot = fromVC.view.snapshotView(afterScreenUpdates: true) else {
return return
} }
toVC.presentedViewController?.view.addSubview(snapshot) toVC.presentedViewController?.view.addSubview(snapshot)
} }
toVC.dismiss(animated: true) toVC.dismiss(animated: true)
} }
/** /**
Replace the current view controller with another view controller within the Replace the current view controller with another view controller within the
navigation/modal stack. navigation/modal stack.
...@@ -288,35 +296,35 @@ extension UIViewController { ...@@ -288,35 +296,35 @@ extension UIViewController {
print("motionReplaceViewController cancelled because Motion was doing a transition. Use Motion.shared.cancel(animated: false) or Motion.shared.end(animated: false) to stop the transition first before calling motionReplaceViewController.") print("motionReplaceViewController cancelled because Motion was doing a transition. Use Motion.shared.cancel(animated: false) or Motion.shared.end(animated: false) to stop the transition first before calling motionReplaceViewController.")
return return
} }
if let nc = navigationController { if let nc = navigationController {
var v = nc.childViewControllers var v = nc.childViewControllers
if !v.isEmpty { if !v.isEmpty {
v.removeLast() v.removeLast()
v.append(next) v.append(next)
} }
if nc.isMotionEnabled { if nc.isMotionEnabled {
Motion.shared.forceNonInteractive = true Motion.shared.forceNonInteractive = true
} }
nc.setViewControllers(v, animated: true) nc.setViewControllers(v, animated: true)
} else if let container = view.superview { } else if let container = view.superview {
let presentingVC = presentingViewController let presentingVC = presentingViewController
Motion.shared.transition(from: self, to: next, in: container) { [weak self] (isFinished) in Motion.shared.transition(from: self, to: next, in: container) { [weak self] (isFinished) in
guard isFinished else { guard isFinished else {
return return
} }
UIApplication.shared.keyWindow?.addSubview(next.view) UIApplication.shared.keyWindow?.addSubview(next.view)
guard let pvc = presentingVC else { guard let pvc = presentingVC else {
UIApplication.shared.keyWindow?.rootViewController = next UIApplication.shared.keyWindow?.rootViewController = next
return return
} }
self?.dismiss(animated: false) { self?.dismiss(animated: false) {
pvc.present(next, animated: false) pvc.present(next, animated: false)
} }
......
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