         }
 
         // Release the current selected item (room/contact/group...).
-        masterTabBarController.releaseSelectedItem()
+        self.tabBarCoordinator?.releaseSelectedItems()
     }
     
     func popToHome(animated: Bool, completion: (() -> Void)?) {
-        if let secondNavController = self.secondaryNavigationController() {
+        if let secondNavController = self.detailNavigationController {
             secondNavController.popToRootViewController(animated: animated)
         }
 
         // Force back to the main screen if this is not the one that is displayed
-        if masterTabBarController != masterNavigationController.visibleViewController {
-            // Listen to the masterNavigationController changes
-            // We need to be sure that masterTabBarController is back to the screen
-            popToHomeViewControllerCompletion = completion
-            masterNavigationController.delegate = self
-
-            masterNavigationController.popToViewController(masterTabBarController, animated: animated)
-        } else {
-            // Select the Home tab
-            masterTabBarController.selectedIndex = Int(TABBAR_HOME_INDEX)
-            completion?()
-        }
+        self.tabBarCoordinator?.popToHome(animated: animated, completion: completion)
     }
     
     // MARK: - Private methods
     
     private func createPlaceholderDetailsViewController() -> UIViewController {
-        let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
-        let emptyDetailsViewController = storyboard.instantiateViewController(withIdentifier: "EmptyDetailsViewControllerStoryboardId")
-        return emptyDetailsViewController
+        return PlaceholderDetailViewController.instantiate()
     }
     
-    func secondaryNavigationController() -> UINavigationController? {
-        guard splitViewController.viewControllers.count == 2, let secondViewController = splitViewController.viewControllers.last as? UINavigationController else {
-            return nil
-        }
-        return secondViewController
+    private func createTabBarCoordinator() -> TabBarCoordinator {
+        let tabBarCoordinator = TabBarCoordinator(session: self.session)
+        tabBarCoordinator.delegate = self
+        return tabBarCoordinator
+    }
+    
+    private func createDetailNavigationController() -> UINavigationController {
+        let placeholderDetailViewController = self.createPlaceholderDetailsViewController()
+        let detailNavigationController = RiotNavigationController(rootViewController: placeholderDetailViewController)
+        return detailNavigationController
     }
 }
 

    }
    
    func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool {
        if (masterTabBarController.currentRoomViewController == nil) && (masterTabBarController.currentContactDetailViewController == nil) && (masterTabBarController.currentGroupDetailViewController == nil) {
            // Return YES to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.
            return true
        } else {
            return false
        }
    }
}

// MARK: - UINavigationControllerDelegate
extension SplitViewCoordinator: UINavigationControllerDelegate {
    
    func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
        
        if viewController == masterTabBarController {
            masterNavigationController.delegate = nil
            
            // For unknown reason, the navigation bar is not restored correctly by [popToViewController:animated:]
            // when a ViewController has hidden it (see MXKAttachmentsViewController).
            // Patch: restore navigation bar by default here.
            masterNavigationController.isNavigationBarHidden = false

            // Release the current selected item (room/contact/...).
            masterTabBarController.releaseSelectedItem()

            if let popToHomeViewControllerCompletion = self.popToHomeViewControllerCompletion {
                let popToHomeViewControllerCompletion2: (() -> Void)? = popToHomeViewControllerCompletion
                self.popToHomeViewControllerCompletion = nil

                DispatchQueue.main.async {
                    popToHomeViewControllerCompletion2?()
                }
            }
        }
        
    }
}

    
    // MARK: - Setup
    
    // TODO: Improve sessions injection
    // at the moment the session is not used, see TabBarCoordinator `init`.
    init(router: RootRouterType, session: MXSession?) {
        self.rootRouter = router
        self.session = session
        
        let splitViewController = UISplitViewController()
        splitViewController.preferredDisplayMode = .allVisible
        self.splitViewController = splitViewController
    }
    
    // MARK: - Public methods
    
    func start() {
        self.splitViewController.delegate = self
        
        let tabBarCoordinator = self.createTabBarCoordinator()
        tabBarCoordinator.delegate = self
        tabBarCoordinator.splitViewMasterPresentableDelegate = self
        tabBarCoordinator.start()
        let detailNavigationController = self.createDetailNavigationController()
        
        self.splitViewController.viewControllers = [tabBarCoordinator.toPresentable(), detailNavigationController]
                
        self.add(childCoordinator: tabBarCoordinator)
        
        self.tabBarCoordinator = tabBarCoordinator
        self.masterPresentable = tabBarCoordinator
        self.detailNavigationController = detailNavigationController
        
        self.rootRouter.setRootModule(self.splitViewController)
    }
    
