From 4ade260277a3863bfcef0d60e844fd4b24a27dc6 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Tue, 28 Feb 2023 12:42:28 +0200 Subject: [PATCH] Fix bug in which teardowns can be called multiple times on the same coordinator --- .../Navigation/NavigationCoordinators.swift | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/ElementX/Sources/Application/Navigation/NavigationCoordinators.swift b/ElementX/Sources/Application/Navigation/NavigationCoordinators.swift index 52cec3f64..80599a862 100644 --- a/ElementX/Sources/Application/Navigation/NavigationCoordinators.swift +++ b/ElementX/Sources/Application/Navigation/NavigationCoordinators.swift @@ -229,15 +229,13 @@ class NavigationSplitCoordinator: CoordinatorProtocol, ObservableObject, CustomS /// /// For added complexity, the NavigationSplitCoordinator has an internal compact layout NavigationStack for which we need to manually nil things again private func releaseAllCoordinatorReferences() { - sidebarModule?.tearDown() - detailModule?.tearDown() - sheetModule?.tearDown() - fullScreenCoverModule?.tearDown() + sidebarModule = nil + detailModule = nil + sheetModule = nil + fullScreenCoverModule = nil - compactLayoutRootModule?.tearDown() - compactLayoutStackModules.forEach { module in - module.tearDown() - } + compactLayoutRootModule = nil + compactLayoutStackModules.removeAll() } private func logPresentationChange(_ change: String, _ module: NavigationModule) { @@ -626,13 +624,10 @@ class NavigationStackCoordinator: ObservableObject, CoordinatorProtocol, CustomS /// when a NavigationModule is dismissed. As the NavigationModule is just a wrapper multiple instances of it continuing living is of no consequence /// https://stackoverflow.com/questions/73885353/found-a-strange-behaviour-of-state-when-combined-to-the-new-navigation-stack/ func stop() { - rootModule?.tearDown() - sheetModule?.tearDown() - fullScreenCoverModule?.tearDown() - - stackModules.forEach { module in - module.tearDown() - } + rootModule = nil + sheetModule = nil + fullScreenCoverModule = nil + stackModules.removeAll() } // MARK: - CustomStringConvertible