From 11cce2d9203363b6dce9a5c722fc29216aea416f Mon Sep 17 00:00:00 2001 From: Alexey Gerasimov Date: Fri, 30 Mar 2018 19:22:19 +0300 Subject: [PATCH 1/3] Change root controller fixed --- CHANGELOG.md | 4 ++++ LeadKit.podspec | 2 +- Sources/Extensions/UIWindow/UIWindow+Extensions.swift | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 275eab44..2e0463d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### 0.7.2 + +- **Fixed**: Change root controller for window + ### 0.7.1 - **Add**: Extension for comparing optional arrays (`[T]?`) with `Equatable` elements. - **Add**: `additionalHttpHeaders` static field in `ConfigurableNetworkService` protocol. diff --git a/LeadKit.podspec b/LeadKit.podspec index 7874d965..79bec383 100644 --- a/LeadKit.podspec +++ b/LeadKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "LeadKit" - s.version = "0.7.1" + s.version = "0.7.2" s.summary = "iOS framework with a bunch of tools for rapid development" s.homepage = "https://github.com/TouchInstinct/LeadKit" s.license = "Apache License, Version 2.0" diff --git a/Sources/Extensions/UIWindow/UIWindow+Extensions.swift b/Sources/Extensions/UIWindow/UIWindow+Extensions.swift index 22514fc5..3bf79ee9 100644 --- a/Sources/Extensions/UIWindow/UIWindow+Extensions.swift +++ b/Sources/Extensions/UIWindow/UIWindow+Extensions.swift @@ -35,7 +35,11 @@ public extension UIWindow { func changeRootController(controller: UIViewController) { animateRootViewControllerChanging(controller: controller) - rootViewController?.dismiss(animated: false, completion: nil) + let previousRoot = rootViewController + previousRoot?.dismiss(animated: false) { + previousRoot?.view.removeFromSuperview() + } + rootViewController = controller makeKeyAndVisible() } From 828d63838cc4d0850ef5ae40cc41c9a6138ce554 Mon Sep 17 00:00:00 2001 From: Alexey Gerasimov Date: Fri, 30 Mar 2018 19:27:30 +0300 Subject: [PATCH 2/3] Refactored --- .../Extensions/UIWindow/UIWindow+Extensions.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sources/Extensions/UIWindow/UIWindow+Extensions.swift b/Sources/Extensions/UIWindow/UIWindow+Extensions.swift index 3bf79ee9..b265b67a 100644 --- a/Sources/Extensions/UIWindow/UIWindow+Extensions.swift +++ b/Sources/Extensions/UIWindow/UIWindow+Extensions.swift @@ -32,12 +32,14 @@ public extension UIWindow { /// Method changes root controller in window. /// /// - Parameter controller: New root controller. - func changeRootController(controller: UIViewController) { - animateRootViewControllerChanging(controller: controller) + /// - Parameter animated: Indicates whether to use animation or not. + func changeRootController(controller: UIViewController, animated: Bool = true) { + if animated { + animateRootViewControllerChanging(controller: controller) + } - let previousRoot = rootViewController - previousRoot?.dismiss(animated: false) { - previousRoot?.view.removeFromSuperview() + rootViewController?.dismiss(animated: false) { [weak self] in + self?.rootViewController?.view.removeFromSuperview() } rootViewController = controller From 63324eec7e303587e2ecb5025a9160b45815cfe7 Mon Sep 17 00:00:00 2001 From: Alexey Gerasimov Date: Fri, 30 Mar 2018 19:32:23 +0300 Subject: [PATCH 3/3] Ooops --- Sources/Extensions/UIWindow/UIWindow+Extensions.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/Extensions/UIWindow/UIWindow+Extensions.swift b/Sources/Extensions/UIWindow/UIWindow+Extensions.swift index b265b67a..b9cc0f05 100644 --- a/Sources/Extensions/UIWindow/UIWindow+Extensions.swift +++ b/Sources/Extensions/UIWindow/UIWindow+Extensions.swift @@ -38,8 +38,9 @@ public extension UIWindow { animateRootViewControllerChanging(controller: controller) } - rootViewController?.dismiss(animated: false) { [weak self] in - self?.rootViewController?.view.removeFromSuperview() + let previousRoot = rootViewController + previousRoot?.dismiss(animated: false) { + previousRoot?.view.removeFromSuperview() } rootViewController = controller