diff --git a/ReMVVMExt/Sources/Navigation.swift b/ReMVVMExt/Sources/Navigation.swift index 02297dc..17de2fb 100644 --- a/ReMVVMExt/Sources/Navigation.swift +++ b/ReMVVMExt/Sources/Navigation.swift @@ -9,7 +9,6 @@ import ReMVVMCore public protocol NavigationState: StoreState { - var navigation: Navigation { get } } diff --git a/ReMVVMExt/Sources/Reducers/DismissModalReducer.swift b/ReMVVMExt/Sources/Reducers/DismissModalReducer.swift index 03a56cb..3c4579b 100644 --- a/ReMVVMExt/Sources/Reducers/DismissModalReducer.swift +++ b/ReMVVMExt/Sources/Reducers/DismissModalReducer.swift @@ -47,9 +47,9 @@ public struct DismissModalMiddleware: Middleware { //dismiss not needed modals if action.dismissAllViews { - uiState.dismissAll(animated: action.animated) + uiState.dismissAll(animated: action.animated, completion: action.completion) } else { - uiState.dismiss(animated: action.animated) + uiState.dismiss(animated: action.animated, completion: action.completion) } } diff --git a/ReMVVMExt/Sources/Reducers/PushReducer.swift b/ReMVVMExt/Sources/Reducers/PushReducer.swift index 47b4a8b..189836f 100644 --- a/ReMVVMExt/Sources/Reducers/PushReducer.swift +++ b/ReMVVMExt/Sources/Reducers/PushReducer.swift @@ -71,7 +71,8 @@ public struct PushMiddleware: Middleware { //dismiss not needed modals uiState.dismiss(animated: action.controllerInfo.animated, - number: uiState.modalControllers.count - state.navigation.modals.count) + number: uiState.modalControllers.count - state.navigation.modals.count, + completion: nil) guard let navigationController = uiState.navigationController else { assertionFailure("PushMiddleware: No navigation Controller") diff --git a/ReMVVMExt/Sources/Reducers/ShowModalReducer.swift b/ReMVVMExt/Sources/Reducers/ShowModalReducer.swift index 8603611..fa1ddb9 100644 --- a/ReMVVMExt/Sources/Reducers/ShowModalReducer.swift +++ b/ReMVVMExt/Sources/Reducers/ShowModalReducer.swift @@ -53,7 +53,8 @@ public struct ShowModalMiddleware: Middleware { //dismiss not needed modals uiState.dismiss(animated: action.controllerInfo.animated, - number: uiState.modalControllers.count - state.navigation.modals.count + 1) + number: uiState.modalControllers.count - state.navigation.modals.count + 1, + completion: nil) let newModal: UIViewController if action.withNavigationController { @@ -70,7 +71,7 @@ public struct ShowModalMiddleware: Middleware { } newModal.modalPresentationStyle = action.presentationStyle - uiState.present(newModal, animated: action.controllerInfo.animated) + uiState.present(newModal, animated: action.controllerInfo.animated, completion: action.completion) } } } diff --git a/ReMVVMExt/Sources/StoreActions.swift b/ReMVVMExt/Sources/StoreActions.swift index cf3d939..f0504c9 100644 --- a/ReMVVMExt/Sources/StoreActions.swift +++ b/ReMVVMExt/Sources/StoreActions.swift @@ -96,6 +96,7 @@ public struct ShowModal: StoreAction { public let showOverSplash: Bool public let showOverSelfType: Bool public let presentationStyle: UIModalPresentationStyle + public let completion: (() -> Void)? public init(loader: Loader, factory: ViewModelFactory? = nil, @@ -103,7 +104,8 @@ public struct ShowModal: StoreAction { withNavigationController: Bool = true, showOverSplash: Bool = true, showOverSelfType: Bool = true, - presentationStyle: UIModalPresentationStyle = .fullScreen) { + presentationStyle: UIModalPresentationStyle = .fullScreen, + completion: (() -> Void)? = nil) { self.controllerInfo = LoaderWithFactory(loader: loader, factory: factory, @@ -112,6 +114,7 @@ public struct ShowModal: StoreAction { self.showOverSplash = showOverSplash self.showOverSelfType = showOverSelfType self.presentationStyle = presentationStyle + self.completion = completion } } @@ -119,10 +122,12 @@ public struct DismissModal: StoreAction { public let dismissAllViews: Bool public let animated: Bool + public let completion: (() -> Void)? - public init(dismissAllViews: Bool = false, animated: Bool = true) { + public init(dismissAllViews: Bool = false, animated: Bool = true, completion: (() -> Void)? = nil) { self.dismissAllViews = dismissAllViews self.animated = animated + self.completion = completion } } diff --git a/ReMVVMExt/Sources/UIState.swift b/ReMVVMExt/Sources/UIState.swift index 5c756f4..b706681 100644 --- a/ReMVVMExt/Sources/UIState.swift +++ b/ReMVVMExt/Sources/UIState.swift @@ -74,23 +74,28 @@ public final class UIState { return modalControllers.last ?? rootViewController } - public func present(_ viewController: UIViewController, animated: Bool) { + public func present(_ viewController: UIViewController, animated: Bool, completion: (() -> Void)?) { topPresenter.present(viewController, animated: animated, completion: { [topPresenter] in topPresenter.setNeedsStatusBarAppearanceUpdate() + completion?() }) modalControllers.append(viewController) } - public func dismissAll(animated: Bool) { - dismiss(animated: animated, number: Int.max) + public func dismissAll(animated: Bool, completion: (() -> Void)?) { + dismiss(animated: animated, number: Int.max, completion: completion) } - public func dismiss(animated: Bool, number: Int = 1) { + public func dismiss(animated: Bool, number: Int = 1, completion: (() -> Void)?) { let number = modalControllers.count >= number ? number : modalControllers.count - guard number > 0 else { return } + guard number > 0 else { + completion?() + return + } modalControllers.removeLast(number) topPresenter.dismiss(animated: animated, completion: { [topPresenter] in topPresenter.setNeedsStatusBarAppearanceUpdate() + completion?() }) } }