Switch callbacks to combine (#1710)

* #750 - Convert the SoftLogoutScreen to combine

* #750 - Convert the UserSessionFlowCoordinator to Combine

* #750 - Convert the AnalyticsPromptScreen to Combine

* #750 - Convert the LoginScreen to Combine

* #750 - Convert the ServerSelectionScreen to Combine

* #750 - Convert the EmojiPickerScreen to Combine

* #750 - Convert the HomeScreen to Combine

* #750 - Convert the MediaUploadPreviewScreen to Combine

* #750 - Convert the OnboardingScreen to Combine

* Rename `Onboarding` to `OnboardingScreen`

* #750 - Convert the ReportContentScreen to Combine

* #750 - Convert the RoomDetailsSscreen to Combine

* #750 - Convert the RoomMemberDetailsScreen to Combine

* #750 - Convert the RoomMembersListScreen to Combine

* #750 - Convert the SessionVerificationScreen to Combine

* #750 - Convert the SettingsScreen to Combine

* #750 - Convert the AdvancedSettingsScreen to Combine

* #750 - Convert the DeveloperOptionsScreen to Combine

* Fix the unit tests

* Use .sink action and the same cancellables constructor everywhere

* Cleanup cancellables when setting up tests
This commit is contained in:
Stefan Ceriu
2023-09-14 12:53:33 +03:00
committed by GitHub
parent a0d40b6f0c
commit a4e5e4f0ed
89 changed files with 884 additions and 589 deletions
@@ -51,7 +51,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
private var appDelegateObserver: AnyCancellable?
private var userSessionObserver: AnyCancellable?
private var clientProxyObserver: AnyCancellable?
private var networkMonitorObserver: AnyCancellable?
private var cancellables = Set<AnyCancellable>()
let notificationManager: NotificationManagerProtocol
@@ -374,15 +374,20 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
keyBackupNeeded: false,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
let coordinator = SoftLogoutScreenCoordinator(parameters: parameters)
coordinator.callback = { result in
switch result {
case .signedIn(let session):
self.userSession = session
self.stateMachine.processEvent(.createdUserSession)
case .clearAllData:
self.stateMachine.processEvent(.signOut(isSoft: false))
coordinator.actions
.sink { [weak self] action in
guard let self else { return }
switch action {
case .signedIn(let session):
self.userSession = session
stateMachine.processEvent(.createdUserSession)
case .clearAllData:
stateMachine.processEvent(.signOut(isSoft: false))
}
}
}
.store(in: &cancellables)
navigationRootCoordinator.setRootCoordinator(coordinator)
}
@@ -401,14 +406,18 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
appSettings: appSettings,
analytics: ServiceLocator.shared.analytics)
userSessionFlowCoordinator.callback = { [weak self] action in
switch action {
case .signOut:
self?.stateMachine.processEvent(.signOut(isSoft: false))
case .clearCache:
self?.stateMachine.processEvent(.clearCache)
userSessionFlowCoordinator.actions
.sink { [weak self] action in
guard let self else { return }
switch action {
case .signOut:
stateMachine.processEvent(.signOut(isSoft: false))
case .clearCache:
stateMachine.processEvent(.clearCache)
}
}
}
.store(in: &cancellables)
userSessionFlowCoordinator.start()
@@ -528,7 +537,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
private func observeNetworkState() {
let reachabilityNotificationIdentifier = "io.element.elementx.reachability.notification"
networkMonitorObserver = ServiceLocator.shared.networkMonitor
ServiceLocator.shared.networkMonitor
.reachabilityPublisher
.removeDuplicates()
.sink { reachability in
@@ -542,6 +551,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
persistent: true))
}
}
.store(in: &cancellables)
}
private func handleAppRoute(_ appRoute: AppRoute) {