diff --git a/TICoordinatorKit.podspec b/TICoordinatorKit.podspec index 342c394..939c498 100644 --- a/TICoordinatorKit.podspec +++ b/TICoordinatorKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'TICoordinatorKit' - s.version = '1.1.5' + s.version = '1.1.7' s.summary = 'A framework for performing navigation in iOS application.' s.homepage = 'https://github.com/TouchInstinct/TICoordinatorKit' s.license = 'Apache License, Version 2.0' diff --git a/TICoordinatorKit/Classes/Routable/Modal/ModalRouter.swift b/TICoordinatorKit/Classes/Routable/Modal/ModalRouter.swift index 90ba5e5..e49bd03 100644 --- a/TICoordinatorKit/Classes/Routable/Modal/ModalRouter.swift +++ b/TICoordinatorKit/Classes/Routable/Modal/ModalRouter.swift @@ -72,11 +72,18 @@ public final class ModalRouter: ModalRoutable { } public func dismissModule(animated: Bool, completion: (() -> ())?) { - rootController?.dismiss(animated: animated) { [weak self] in - self?.topController = self?.rootController - self?.childRootControllers = [] + let dismissCompletion = { + self.topController = self.rootController + self.childRootControllers = [] completion?() } + + guard rootController?.presentedViewController != nil else { + dismissCompletion() + return + } + + rootController?.dismiss(animated: animated, completion: dismissCompletion) } public func presentChild(_ module: Presentable?, diff --git a/TICoordinatorKit/Classes/Routable/Stack/StackRoutable.swift b/TICoordinatorKit/Classes/Routable/Stack/StackRoutable.swift index 7f75923..e6d32dd 100644 --- a/TICoordinatorKit/Classes/Routable/Stack/StackRoutable.swift +++ b/TICoordinatorKit/Classes/Routable/Stack/StackRoutable.swift @@ -51,3 +51,21 @@ public protocol StackRoutable: ModalRoutable { func pop(to module: Presentable?) func pop(to module: Presentable?, animated: Bool) } + +public extension StackRoutable { + var headModuleInTheStack: Bool { + if let headModule = headModule, headModule.toPresent()?.parent === toPresent() { + return true + } + + return false + } + + func withAnimationCompletion(_ animationCompletion: (() -> Void)?, + routerActions: (StackRoutable) -> Void) { + CATransaction.begin() + CATransaction.setCompletionBlock(animationCompletion) + routerActions(self) + CATransaction.commit() + } +}