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)
}
func stop() {
hideLoadingIndicator()
}
// MARK: - Private
private func setupLogging() {

View File

@ -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 }
}
}

View File

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

View File

@ -47,6 +47,10 @@ class AuthenticationCoordinator: Coordinator, Presentable {
func toPresentable() -> UIViewController {
navigationRouter.toPresentable()
}
func stop() {
stopLoading()
}
// MARK: - Private

View File

@ -99,6 +99,10 @@ final class LoginCoordinator: Coordinator, Presentable {
func toPresentable() -> UIViewController {
loginHostingController
}
func stop() {
stopLoading()
}
// MARK: - Private

View File

@ -82,6 +82,10 @@ final class ServerSelectionCoordinator: Coordinator, Presentable {
func toPresentable() -> UIViewController {
serverSelectionHostingController
}
func stop() {
stopLoading()
}
// MARK: - Private

View File

@ -108,6 +108,10 @@ final class SoftLogoutCoordinator: Coordinator, Presentable {
func toPresentable() -> UIViewController {
softLogoutHostingController
}
func stop() {
stopLoading()
}
// MARK: - Private

View File

@ -77,6 +77,10 @@ final class BugReportCoordinator: Coordinator, Presentable {
func toPresentable() -> UIViewController {
bugReportHostingController
}
func stop() {
stopLoading()
}
// MARK: - Private

View File

@ -79,6 +79,8 @@ final class HomeScreenCoordinator: Coordinator, Presentable {
func toPresentable() -> UIViewController {
hostingController
}
func stop() { }
// MARK: - Private

View File

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

View File

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

View File

@ -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

View File

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

View File

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

View File

@ -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)
}

View File

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

View File

@ -87,6 +87,8 @@ final class SettingsCoordinator: Coordinator, Presentable {
func toPresentable() -> UIViewController {
settingsHostingController
}
func stop() { }
// MARK: - Private

View File

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

View File

@ -75,6 +75,10 @@ final class TemplateCoordinator: Coordinator, Presentable {
func toPresentable() -> UIViewController {
templateHostingController
}
func stop() {
stopLoading()
}
// MARK: - Private