Commit b0e21e3b by Daniel Dahan

updated Extensions

parent de05a397
...@@ -41,3 +41,4 @@ internal extension Array { ...@@ -41,3 +41,4 @@ internal extension Array {
return nil return nil
} }
} }
...@@ -143,6 +143,7 @@ extension UIViewController { ...@@ -143,6 +143,7 @@ extension UIViewController {
previousTabBarDelegate = v.delegate previousTabBarDelegate = v.delegate
v.delegate = Motion.shared v.delegate = Motion.shared
} }
} else { } else {
transitioningDelegate = nil transitioningDelegate = nil
...@@ -228,62 +229,60 @@ extension UIViewController { ...@@ -228,62 +229,60 @@ extension UIViewController {
/// 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? = nil
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() {
if self != v, withMatchBlock(v) { for vc in childViewControllers.reversed() {
target = v if self != vc, withMatchBlock(vc) {
target = vc
break break
} }
} }
} }
guard nil == target else { if nil == target {
continue current = current!.presentingViewController
}
if let vc = current, true == withMatchBlock(vc) {
current = current?.presentingViewController target = vc
}
guard let v = current, withMatchBlock(v) else {
continue
} }
target = v
} }
guard let v = target else { guard let t = target else {
return return
} }
guard nil != v.presentedViewController else { guard nil != t.presentedViewController else {
v.navigationController?.popToViewController(v, animated: true) _ = t.navigationController?.popToViewController(t, animated: true)
return return
} }
v.navigationController?.popToViewController(v, animated: false) _ = t.navigationController?.popToViewController(t, animated: false)
let fromVC = navigationController ?? self let fvc = navigationController ?? self
let toVC = v.navigationController ?? v let tvc = t.navigationController ?? t
if v.presentedViewController != fromVC { if t.presentedViewController != fvc {
/** // 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. // We overcome this behavior by inserting a snapshot into target.presentedViewController
We overcome this behavior by inserting a snapshot into target.presentedViewController // And also force Hero to use the current VC as the fromViewController
And also force Motion to use the current view controller as the fromViewController. Motion.shared.fromViewController = fvc
*/
Motion.shared.fromViewController = fromVC let snapshotView = fvc.view.snapshotView(afterScreenUpdates: true)!
let targetSuperview = tvc.presentedViewController!.view!
guard let snapshot = fromVC.view.snapshotView(afterScreenUpdates: true) else {
return 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