//
//  ModuleTransitionHandler.swift
//  SwiftyModuleTransition
//
//  Created by rock88 on 27/05/2017.
//  Copyright © 2017 rock88. All rights reserved.
//

import UIKit

public protocol ModuleTransitionHandler: class {
    func openModule<View: ModuleView>(factory: ModuleFactory<View>) -> ModuleConfigurator
    func close(animated: Bool)
}

extension UIViewController: ModuleTransitionHandler {
    public func openModule<View: ModuleView>(factory: ModuleFactory<View>) -> ModuleConfigurator {
        let view = factory.instantiateModuleTransitionHandler()
        return ModuleConfiguratorImpl(source: self, destination: view, output: view.output)
    }
    
    public func close(animated: Bool) {
        if let _ = presentingViewController {
            dismiss(animated: animated, completion: nil)
        } else if let navigationController = navigationController, navigationController.viewControllers.count > 0 {
            navigationController.popViewController(animated: animated)
        } else if let _ = view.superview {
            view.removeFromSuperview()
        }
    }
}

//
//  ModuleTransitionHandler.swift
//  SwiftyModuleTransition
//
//  Created by rock88 on 27/05/2017.
//  Copyright © 2017 rock88. All rights reserved.
//

import UIKit

public protocol ModuleTransitionHandler: class {
    func openModule<View: ModuleView>(factory: ModuleFactory<View>) -> ModuleConfigurator
    func close()
}

extension UIViewController: ModuleTransitionHandler {
    public func openModule<View: ModuleView>(factory: ModuleFactory<View>) -> ModuleConfigurator {
        let view = factory.instantiateModuleTransitionHandler()
        return ModuleConfiguratorImpl(source: self, destination: view, output: view.output)
    }
    
    public func close() {
        if let _ = presentingViewController {
            dismiss(animated: true, completion: nil)
        } else if let navigationController = navigationController, navigationController.viewControllers.count > 0 {
            navigationController.popViewController(animated: true)
        } else {
            view.removeFromSuperview()
        }
    }
}

--- 
+++ 
@@ -10,7 +10,7 @@
 
 public protocol ModuleTransitionHandler: class {
     func openModule<View: ModuleView>(factory: ModuleFactory<View>) -> ModuleConfigurator
-    func close()
+    func close(animated: Bool)
 }
 
 extension UIViewController: ModuleTransitionHandler {
@@ -19,12 +19,12 @@
         return ModuleConfiguratorImpl(source: self, destination: view, output: view.output)
     }
     
-    public func close() {
+    public func close(animated: Bool) {
         if let _ = presentingViewController {
-            dismiss(animated: true, completion: nil)
+            dismiss(animated: animated, completion: nil)
         } else if let navigationController = navigationController, navigationController.viewControllers.count > 0 {
-            navigationController.popViewController(animated: true)
-        } else {
+            navigationController.popViewController(animated: animated)
+        } else if let _ = view.superview {
             view.removeFromSuperview()
         }
     }
Add animated arg to close()
