From b03a02351a44f5a4816596678955cd81f74b4b5d Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Fri, 23 Sep 2022 15:04:35 +0300 Subject: [PATCH] Coordinator stops (#207) * Add `stop` method to `Coordinator` * Use new stop method to cleanup room screen * Call stop implicitly when removing a child coordinator * Revert placeholder avatar font change * Fix PR remarks --- ElementX/Sources/AppCoordinator.swift | 4 ++++ ElementX/Sources/Other/Coordinator.swift | 4 ++++ .../AnalyticsPrompt/AnalyticsPromptCoordinator.swift | 2 ++ .../Authentication/AuthenticationCoordinator.swift | 4 ++++ .../Authentication/LoginScreen/LoginCoordinator.swift | 4 ++++ .../ServerSelection/ServerSelectionCoordinator.swift | 4 ++++ .../SoftLogout/SoftLogoutCoordinator.swift | 4 ++++ .../Screens/BugReport/BugReportCoordinator.swift | 4 ++++ .../Screens/HomeScreen/HomeScreenCoordinator.swift | 2 ++ .../Screens/RoomScreen/RoomScreenCoordinator.swift | 4 ++++ .../Sources/Screens/RoomScreen/RoomScreenModels.swift | 1 - .../Screens/RoomScreen/RoomScreenViewModel.swift | 10 ++++++---- .../RoomScreen/RoomScreenViewModelProtocol.swift | 2 ++ .../Sources/Screens/RoomScreen/View/RoomScreen.swift | 3 --- .../View/Timeline/PlaceholderAvatarImage.swift | 3 ++- .../SessionVerificationCoordinator.swift | 2 ++ .../Sources/Screens/Settings/SettingsCoordinator.swift | 2 ++ ElementX/Sources/UITestsAppCoordinator.swift | 2 ++ .../ElementX/TemplateCoordinator.swift | 4 ++++ 19 files changed, 56 insertions(+), 9 deletions(-) diff --git a/ElementX/Sources/AppCoordinator.swift b/ElementX/Sources/AppCoordinator.swift index 820670c06..db09d1f6f 100644 --- a/ElementX/Sources/AppCoordinator.swift +++ b/ElementX/Sources/AppCoordinator.swift @@ -105,6 +105,10 @@ class AppCoordinator: Coordinator { stateMachine.processEvent(userSessionStore.hasSessions ? .startWithExistingSession : .startWithAuthentication) } + func stop() { + hideLoadingIndicator() + } + // MARK: - Private private func setupLogging() { diff --git a/ElementX/Sources/Other/Coordinator.swift b/ElementX/Sources/Other/Coordinator.swift index 323eae256..4a57bc034 100755 --- a/ElementX/Sources/Other/Coordinator.swift +++ b/ElementX/Sources/Other/Coordinator.swift @@ -36,6 +36,9 @@ protocol Coordinator: AnyObject { /// /// - Parameter childCoordinator: Child coordinator to remove. func remove(childCoordinator: Coordinator) + + /// Stops job of the coordinator. Can be used to clear some resources. Will be automatically called when the coordinator removed. + func stop() } // `Coordinator` default implementation @@ -45,6 +48,7 @@ extension Coordinator { } func remove(childCoordinator: Coordinator) { + childCoordinator.stop() childCoordinators = childCoordinators.filter { $0 !== childCoordinator } } } diff --git a/ElementX/Sources/Screens/AnalyticsPrompt/AnalyticsPromptCoordinator.swift b/ElementX/Sources/Screens/AnalyticsPrompt/AnalyticsPromptCoordinator.swift index a73968070..cd64695c7 100644 --- a/ElementX/Sources/Screens/AnalyticsPrompt/AnalyticsPromptCoordinator.swift +++ b/ElementX/Sources/Screens/AnalyticsPrompt/AnalyticsPromptCoordinator.swift @@ -70,4 +70,6 @@ final class AnalyticsPromptCoordinator: Coordinator, Presentable { } func toPresentable() -> UIViewController { analyticsPromptHostingController } + + func stop() { } } diff --git a/ElementX/Sources/Screens/Authentication/AuthenticationCoordinator.swift b/ElementX/Sources/Screens/Authentication/AuthenticationCoordinator.swift index 8509f12e4..a1c996007 100644 --- a/ElementX/Sources/Screens/Authentication/AuthenticationCoordinator.swift +++ b/ElementX/Sources/Screens/Authentication/AuthenticationCoordinator.swift @@ -47,6 +47,10 @@ class AuthenticationCoordinator: Coordinator, Presentable { func toPresentable() -> UIViewController { navigationRouter.toPresentable() } + + func stop() { + stopLoading() + } // MARK: - Private diff --git a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginCoordinator.swift b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginCoordinator.swift index 98c328546..4e322b346 100644 --- a/ElementX/Sources/Screens/Authentication/LoginScreen/LoginCoordinator.swift +++ b/ElementX/Sources/Screens/Authentication/LoginScreen/LoginCoordinator.swift @@ -99,6 +99,10 @@ final class LoginCoordinator: Coordinator, Presentable { func toPresentable() -> UIViewController { loginHostingController } + + func stop() { + stopLoading() + } // MARK: - Private diff --git a/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionCoordinator.swift b/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionCoordinator.swift index 5228c52d7..087e2e1c9 100644 --- a/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionCoordinator.swift +++ b/ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionCoordinator.swift @@ -82,6 +82,10 @@ final class ServerSelectionCoordinator: Coordinator, Presentable { func toPresentable() -> UIViewController { serverSelectionHostingController } + + func stop() { + stopLoading() + } // MARK: - Private diff --git a/ElementX/Sources/Screens/Authentication/SoftLogout/SoftLogoutCoordinator.swift b/ElementX/Sources/Screens/Authentication/SoftLogout/SoftLogoutCoordinator.swift index a8bbd448f..21e8a3587 100644 --- a/ElementX/Sources/Screens/Authentication/SoftLogout/SoftLogoutCoordinator.swift +++ b/ElementX/Sources/Screens/Authentication/SoftLogout/SoftLogoutCoordinator.swift @@ -108,6 +108,10 @@ final class SoftLogoutCoordinator: Coordinator, Presentable { func toPresentable() -> UIViewController { softLogoutHostingController } + + func stop() { + stopLoading() + } // MARK: - Private diff --git a/ElementX/Sources/Screens/BugReport/BugReportCoordinator.swift b/ElementX/Sources/Screens/BugReport/BugReportCoordinator.swift index 9afc2bfaa..e8484501f 100644 --- a/ElementX/Sources/Screens/BugReport/BugReportCoordinator.swift +++ b/ElementX/Sources/Screens/BugReport/BugReportCoordinator.swift @@ -77,6 +77,10 @@ final class BugReportCoordinator: Coordinator, Presentable { func toPresentable() -> UIViewController { bugReportHostingController } + + func stop() { + stopLoading() + } // MARK: - Private diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenCoordinator.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenCoordinator.swift index 73b9ae31a..041880db6 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenCoordinator.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenCoordinator.swift @@ -79,6 +79,8 @@ final class HomeScreenCoordinator: Coordinator, Presentable { func toPresentable() -> UIViewController { hostingController } + + func stop() { } // MARK: - Private diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift index 20d8335ed..81755d2f5 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift @@ -58,4 +58,8 @@ final class RoomScreenCoordinator: Coordinator, Presentable { func toPresentable() -> UIViewController { roomScreenHostingController } + + func stop() { + roomScreenViewModel.stop() + } } diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift index 73e3224ac..69af08ffc 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift @@ -40,7 +40,6 @@ enum RoomScreenViewAction { case sendMessage case sendReaction(key: String, eventID: String) case cancelReply - case viewDisappeared } struct RoomScreenViewState: BindableState { diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift index 2d45945f3..bdc4da95e 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift @@ -90,12 +90,14 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol MXLog.warning("React with \(key) failed. Not implemented.") case .cancelReply: state.composerMode = .default - case .viewDisappeared: - cancellables.forEach { $0.cancel() } - cancellables.removeAll() - state.contextMenuBuilder = nil } } + + func stop() { + cancellables.forEach { $0.cancel() } + cancellables.removeAll() + state.contextMenuBuilder = nil + } // MARK: - Private diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModelProtocol.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModelProtocol.swift index efd90b1e9..042fd58d9 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModelProtocol.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModelProtocol.swift @@ -19,4 +19,6 @@ import Foundation @MainActor protocol RoomScreenViewModelProtocol { var context: RoomScreenViewModelType.Context { get } + + func stop() } diff --git a/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift b/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift index 3c47522a5..f6db3ce66 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift @@ -41,9 +41,6 @@ struct RoomScreen: View { } } .alert(item: $context.alertInfo) { $0.alert } - .onDisappear { - context.send(viewAction: .viewDisappeared) - } } private func sendMessage() { diff --git a/ElementX/Sources/Screens/RoomScreen/View/Timeline/PlaceholderAvatarImage.swift b/ElementX/Sources/Screens/RoomScreen/View/Timeline/PlaceholderAvatarImage.swift index e7bd59ed9..1b9cfc9a3 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/Timeline/PlaceholderAvatarImage.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/Timeline/PlaceholderAvatarImage.swift @@ -26,7 +26,8 @@ struct PlaceholderAvatarImage: View { Text(textForImage) .padding(4) .foregroundColor(.white) - .font(.title2.bold()) + .font(.system(size: 200).weight(.semibold)) + .minimumScaleFactor(0.001) } .aspectRatio(1, contentMode: .fill) } diff --git a/ElementX/Sources/Screens/SessionVerification/SessionVerificationCoordinator.swift b/ElementX/Sources/Screens/SessionVerification/SessionVerificationCoordinator.swift index fc1ee59f6..c3fa9df62 100644 --- a/ElementX/Sources/Screens/SessionVerification/SessionVerificationCoordinator.swift +++ b/ElementX/Sources/Screens/SessionVerification/SessionVerificationCoordinator.swift @@ -63,4 +63,6 @@ final class SessionVerificationCoordinator: Coordinator, Presentable { func toPresentable() -> UIViewController { sessionVerificationHostingController } + + func stop() { } } diff --git a/ElementX/Sources/Screens/Settings/SettingsCoordinator.swift b/ElementX/Sources/Screens/Settings/SettingsCoordinator.swift index 0578d18a6..bfd3deec3 100644 --- a/ElementX/Sources/Screens/Settings/SettingsCoordinator.swift +++ b/ElementX/Sources/Screens/Settings/SettingsCoordinator.swift @@ -87,6 +87,8 @@ final class SettingsCoordinator: Coordinator, Presentable { func toPresentable() -> UIViewController { settingsHostingController } + + func stop() { } // MARK: - Private diff --git a/ElementX/Sources/UITestsAppCoordinator.swift b/ElementX/Sources/UITestsAppCoordinator.swift index f771ea33f..1be01ce9a 100644 --- a/ElementX/Sources/UITestsAppCoordinator.swift +++ b/ElementX/Sources/UITestsAppCoordinator.swift @@ -60,6 +60,8 @@ class UITestsAppCoordinator: Coordinator { private func mockScreens() -> [MockScreen] { UITestScreenIdentifier.allCases.map { MockScreen(id: $0, navigationRouter: navigationRouter) } } + + func stop() { } } @MainActor diff --git a/Tools/Scripts/Templates/SimpleScreenExample/ElementX/TemplateCoordinator.swift b/Tools/Scripts/Templates/SimpleScreenExample/ElementX/TemplateCoordinator.swift index 963d3c943..b8b53d35a 100644 --- a/Tools/Scripts/Templates/SimpleScreenExample/ElementX/TemplateCoordinator.swift +++ b/Tools/Scripts/Templates/SimpleScreenExample/ElementX/TemplateCoordinator.swift @@ -75,6 +75,10 @@ final class TemplateCoordinator: Coordinator, Presentable { func toPresentable() -> UIViewController { templateHostingController } + + func stop() { + stopLoading() + } // MARK: - Private