Commit b0e21e3b by Daniel Dahan

updated Extensions

parent de05a397
......@@ -41,3 +41,4 @@ internal extension Array {
return nil
}
}
......@@ -143,6 +143,7 @@ extension UIViewController {
previousTabBarDelegate = v.delegate
v.delegate = Motion.shared
}
} else {
transitioningDelegate = nil
......@@ -228,62 +229,60 @@ extension UIViewController {
/// Unwind to a view controller that the matchBlock returns true on.
public func motionUnwindToViewController(withMatchBlock: (UIViewController) -> Bool) {
var target: UIViewController?
var target: UIViewController? = nil
var current: UIViewController? = self
while nil == target && nil != current {
if let childViewControllers = (current as? UINavigationController)?.childViewControllers ?? current!.navigationController?.childViewControllers {
for v in childViewControllers.reversed() {
if self != v, withMatchBlock(v) {
target = v
for vc in childViewControllers.reversed() {
if self != vc, withMatchBlock(vc) {
target = vc
break
}
}
}
guard nil == target else {
continue
}
current = current?.presentingViewController
guard let v = current, withMatchBlock(v) else {
continue
if nil == target {
current = current!.presentingViewController
if let vc = current, true == withMatchBlock(vc) {
target = vc
}
}
target = v
}
guard let v = target else {
guard let t = target else {
return
}
guard nil != v.presentedViewController else {
v.navigationController?.popToViewController(v, animated: true)
guard nil != t.presentedViewController else {
_ = t.navigationController?.popToViewController(t, animated: true)
return
}
v.navigationController?.popToViewController(v, animated: false)
let fromVC = navigationController ?? self
let toVC = v.navigationController ?? v
if v.presentedViewController != fromVC {
/**
UIKit's UIViewController.dismiss will jump to target.presentedViewController then perform the dismiss.
We overcome this behavior by inserting a snapshot into target.presentedViewController
And also force Motion to use the current view controller as the fromViewController.
*/
Motion.shared.fromViewController = fromVC
guard let snapshot = fromVC.view.snapshotView(afterScreenUpdates: true) else {
return
_ = t.navigationController?.popToViewController(t, animated: false)
let fvc = navigationController ?? self
let tvc = t.navigationController ?? t
if t.presentedViewController != fvc {
// UIKit's UIViewController.dismiss will jump to target.presentedViewController then perform the dismiss.
// We overcome this behavior by inserting a snapshot into target.presentedViewController
// And also force Hero to use the current VC as the fromViewController
Motion.shared.fromViewController = fvc
let snapshotView = fvc.view.snapshotView(afterScreenUpdates: true)!
let targetSuperview = tvc.presentedViewController!.view!
if let visualEffectView = targetSuperview as? UIVisualEffectView {
visualEffectView.contentView.addSubview(snapshotView)
} else {
targetSuperview.addSubview(snapshotView)
}
toVC.presentedViewController?.view.addSubview(snapshot)
}
toVC.dismiss(animated: true)
tvc.dismiss(animated: true, completion: nil)
}
/**
......
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