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
This commit is contained in:
ismailgulek 2022-09-23 15:04:35 +03:00 committed by GitHub
parent d7dad1353b
commit b03a02351a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 56 additions and 9 deletions

View File

@ -105,6 +105,10 @@ class AppCoordinator: Coordinator {
stateMachine.processEvent(userSessionStore.hasSessions ? .startWithExistingSession : .startWithAuthentication) stateMachine.processEvent(userSessionStore.hasSessions ? .startWithExistingSession : .startWithAuthentication)
} }
func stop() {
hideLoadingIndicator()
}
// MARK: - Private // MARK: - Private
private func setupLogging() { private func setupLogging() {

View File

@ -36,6 +36,9 @@ protocol Coordinator: AnyObject {
/// ///
/// - Parameter childCoordinator: Child coordinator to remove. /// - Parameter childCoordinator: Child coordinator to remove.
func remove(childCoordinator: Coordinator) 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 // `Coordinator` default implementation
@ -45,6 +48,7 @@ extension Coordinator {
} }
func remove(childCoordinator: Coordinator) { func remove(childCoordinator: Coordinator) {
childCoordinator.stop()
childCoordinators = childCoordinators.filter { $0 !== childCoordinator } childCoordinators = childCoordinators.filter { $0 !== childCoordinator }
} }
} }

View File

@ -70,4 +70,6 @@ final class AnalyticsPromptCoordinator: Coordinator, Presentable {
} }
func toPresentable() -> UIViewController { analyticsPromptHostingController } func toPresentable() -> UIViewController { analyticsPromptHostingController }
func stop() { }
} }

View File

@ -48,6 +48,10 @@ class AuthenticationCoordinator: Coordinator, Presentable {
navigationRouter.toPresentable() navigationRouter.toPresentable()
} }
func stop() {
stopLoading()
}
// MARK: - Private // MARK: - Private
/// Shows the splash screen as the root view in the navigation stack. /// Shows the splash screen as the root view in the navigation stack.

View File

@ -100,6 +100,10 @@ final class LoginCoordinator: Coordinator, Presentable {
loginHostingController loginHostingController
} }
func stop() {
stopLoading()
}
// MARK: - Private // MARK: - Private
/// Show a blocking activity indicator whilst saving. /// Show a blocking activity indicator whilst saving.

View File

@ -83,6 +83,10 @@ final class ServerSelectionCoordinator: Coordinator, Presentable {
serverSelectionHostingController serverSelectionHostingController
} }
func stop() {
stopLoading()
}
// MARK: - Private // MARK: - Private
/// Show an activity indicator whilst loading. /// Show an activity indicator whilst loading.

View File

@ -109,6 +109,10 @@ final class SoftLogoutCoordinator: Coordinator, Presentable {
softLogoutHostingController softLogoutHostingController
} }
func stop() {
stopLoading()
}
// MARK: - Private // MARK: - Private
/// Show an activity indicator whilst loading. /// Show an activity indicator whilst loading.

View File

@ -78,6 +78,10 @@ final class BugReportCoordinator: Coordinator, Presentable {
bugReportHostingController bugReportHostingController
} }
func stop() {
stopLoading()
}
// MARK: - Private // MARK: - Private
/// Show an activity indicator whilst loading. /// Show an activity indicator whilst loading.

View File

@ -80,6 +80,8 @@ final class HomeScreenCoordinator: Coordinator, Presentable {
hostingController hostingController
} }
func stop() { }
// MARK: - Private // MARK: - Private
private func processUserMenuAction(_ action: HomeScreenViewUserMenuAction) { private func processUserMenuAction(_ action: HomeScreenViewUserMenuAction) {

View File

@ -58,4 +58,8 @@ final class RoomScreenCoordinator: Coordinator, Presentable {
func toPresentable() -> UIViewController { func toPresentable() -> UIViewController {
roomScreenHostingController roomScreenHostingController
} }
func stop() {
roomScreenViewModel.stop()
}
} }

View File

@ -40,7 +40,6 @@ enum RoomScreenViewAction {
case sendMessage case sendMessage
case sendReaction(key: String, eventID: String) case sendReaction(key: String, eventID: String)
case cancelReply case cancelReply
case viewDisappeared
} }
struct RoomScreenViewState: BindableState { struct RoomScreenViewState: BindableState {

View File

@ -90,12 +90,14 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
MXLog.warning("React with \(key) failed. Not implemented.") MXLog.warning("React with \(key) failed. Not implemented.")
case .cancelReply: case .cancelReply:
state.composerMode = .default state.composerMode = .default
case .viewDisappeared: }
}
func stop() {
cancellables.forEach { $0.cancel() } cancellables.forEach { $0.cancel() }
cancellables.removeAll() cancellables.removeAll()
state.contextMenuBuilder = nil state.contextMenuBuilder = nil
} }
}
// MARK: - Private // MARK: - Private

View File

@ -19,4 +19,6 @@ import Foundation
@MainActor @MainActor
protocol RoomScreenViewModelProtocol { protocol RoomScreenViewModelProtocol {
var context: RoomScreenViewModelType.Context { get } var context: RoomScreenViewModelType.Context { get }
func stop()
} }

View File

@ -41,9 +41,6 @@ struct RoomScreen: View {
} }
} }
.alert(item: $context.alertInfo) { $0.alert } .alert(item: $context.alertInfo) { $0.alert }
.onDisappear {
context.send(viewAction: .viewDisappeared)
}
} }
private func sendMessage() { private func sendMessage() {

View File

@ -26,7 +26,8 @@ struct PlaceholderAvatarImage: View {
Text(textForImage) Text(textForImage)
.padding(4) .padding(4)
.foregroundColor(.white) .foregroundColor(.white)
.font(.title2.bold()) .font(.system(size: 200).weight(.semibold))
.minimumScaleFactor(0.001)
} }
.aspectRatio(1, contentMode: .fill) .aspectRatio(1, contentMode: .fill)
} }

View File

@ -63,4 +63,6 @@ final class SessionVerificationCoordinator: Coordinator, Presentable {
func toPresentable() -> UIViewController { func toPresentable() -> UIViewController {
sessionVerificationHostingController sessionVerificationHostingController
} }
func stop() { }
} }

View File

@ -88,6 +88,8 @@ final class SettingsCoordinator: Coordinator, Presentable {
settingsHostingController settingsHostingController
} }
func stop() { }
// MARK: - Private // MARK: - Private
private func toggleAnalytics() { private func toggleAnalytics() {

View File

@ -60,6 +60,8 @@ class UITestsAppCoordinator: Coordinator {
private func mockScreens() -> [MockScreen] { private func mockScreens() -> [MockScreen] {
UITestScreenIdentifier.allCases.map { MockScreen(id: $0, navigationRouter: navigationRouter) } UITestScreenIdentifier.allCases.map { MockScreen(id: $0, navigationRouter: navigationRouter) }
} }
func stop() { }
} }
@MainActor @MainActor

View File

@ -76,6 +76,10 @@ final class TemplateCoordinator: Coordinator, Presentable {
templateHostingController templateHostingController
} }
func stop() {
stopLoading()
}
// MARK: - Private // MARK: - Private
/// Show an activity indicator whilst loading. /// Show an activity indicator whilst loading.