Skip to content

Commit

Permalink
Fix unit and UI tests (+6 squashed commits)
Browse files Browse the repository at this point in the history
Squashed commits:
[1ece59e] Fix login flows
[6884dc3] Use modules everywhere the underlying object is a NavigationModule
[ab08d44] Rename navigation components to: SingleScreenCoordinator, SplitScreenCoordinator and StackScreenCoordinator
[8f5d978] Working but incomplete
[c065603] Experimenting
[ada2be5] Add SplitNavigationController
  • Loading branch information
stefanceriu committed Dec 6, 2022
1 parent 7f91852 commit 7115a31
Show file tree
Hide file tree
Showing 15 changed files with 752 additions and 395 deletions.
124 changes: 64 additions & 60 deletions ElementX.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions ElementX/Sources/Application/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import SwiftUI

class AppCoordinator: AppCoordinatorProtocol {
private let stateMachine: AppCoordinatorStateMachine
private let navigationController: NavigationController
private let rootScreenCoordinator: SingleScreenCoordinator
private let userSessionStore: UserSessionStoreProtocol
/// Common background task to resume long-running tasks in the background.
/// When this task expiring, we'll try to suspend the state machine by `suspend` event.
Expand Down Expand Up @@ -51,14 +51,14 @@ class AppCoordinator: AppCoordinatorProtocol {
private(set) var notificationManager: NotificationManagerProtocol?

init() {
navigationController = NavigationController()
rootScreenCoordinator = SingleScreenCoordinator()
stateMachine = AppCoordinatorStateMachine()

bugReportService = BugReportService(withBaseURL: BuildSettings.bugReportServiceBaseURL, sentryURL: BuildSettings.bugReportSentryURL)

navigationController.setRootCoordinator(SplashScreenCoordinator())
rootScreenCoordinator.setRootCoordinator(SplashScreenCoordinator())

ServiceLocator.shared.register(userNotificationController: UserNotificationController(rootCoordinator: navigationController))
ServiceLocator.shared.register(userNotificationController: UserNotificationController(rootCoordinator: rootScreenCoordinator))

backgroundTaskService = UIKitBackgroundTaskService {
UIApplication.shared
Expand Down Expand Up @@ -168,12 +168,15 @@ class AppCoordinator: AppCoordinatorProtocol {
}

private func startAuthentication() {
let authenticationStackScreenCoordinator = StackScreenCoordinator()
let authenticationService = AuthenticationServiceProxy(userSessionStore: userSessionStore)
authenticationCoordinator = AuthenticationCoordinator(authenticationService: authenticationService,
navigationController: navigationController)
stackScreenCoordinator: authenticationStackScreenCoordinator)
authenticationCoordinator?.delegate = self

authenticationCoordinator?.start()

rootScreenCoordinator.setRootCoordinator(authenticationStackScreenCoordinator)
}

private func startAuthenticationSoftLogout() {
Expand Down Expand Up @@ -208,13 +211,13 @@ class AppCoordinator: AppCoordinatorProtocol {
}
}

navigationController.setRootCoordinator(coordinator)
rootScreenCoordinator.setRootCoordinator(coordinator)
}
}

private func setupUserSession() {
let userSessionFlowCoordinator = UserSessionFlowCoordinator(userSession: userSession,
navigationController: navigationController,
rootScreenCoordinator: rootScreenCoordinator,
bugReportService: bugReportService)

userSessionFlowCoordinator.callback = { [weak self] action in
Expand Down Expand Up @@ -253,7 +256,7 @@ class AppCoordinator: AppCoordinatorProtocol {
}

private func presentSplashScreen(isSoftLogout: Bool = false) {
navigationController.setRootCoordinator(SplashScreenCoordinator())
rootScreenCoordinator.setRootCoordinator(SplashScreenCoordinator())

if isSoftLogout {
startAuthenticationSoftLogout()
Expand Down
186 changes: 0 additions & 186 deletions ElementX/Sources/Application/NavigationController.swift

This file was deleted.

34 changes: 34 additions & 0 deletions ElementX/Sources/Application/NavigationModule.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

struct NavigationModule: Identifiable, Hashable {
let id = UUID()
let coordinator: any CoordinatorProtocol

init(_ coordinator: any CoordinatorProtocol) {
self.coordinator = coordinator
}

static func == (lhs: NavigationModule, rhs: NavigationModule) -> Bool {
lhs.id == rhs.id
}

func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
58 changes: 58 additions & 0 deletions ElementX/Sources/Application/SingleScreenCoordinator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import SwiftUI

class SingleScreenCoordinator: ObservableObject, CoordinatorProtocol {
private var dismissalCallbacks = [UUID: () -> Void]()

@Published private(set) var rootModule: NavigationModule? {
didSet {
if let oldValue {
oldValue.coordinator.stop()
}

if let rootModule {
logPresentationChange("Set root", rootModule)
rootModule.coordinator.start()
}
}
}

func setRootCoordinator(_ coordinator: any CoordinatorProtocol) {
rootModule = NavigationModule(coordinator)
}

// MARK: - CoordinatorProtocol

func toPresentable() -> AnyView {
AnyView(SingleScreenCoordinatorView(singleScreenCoordinator: self))
}

// MARK: - Private

private func logPresentationChange(_ change: String, _ module: NavigationModule) {
MXLog.info("\(change): \(module.coordinator)(\(module.id))")
}
}

private struct SingleScreenCoordinatorView: View {
@ObservedObject var singleScreenCoordinator: SingleScreenCoordinator

var body: some View {
singleScreenCoordinator.rootModule?.coordinator.toPresentable()
}
}
Loading

0 comments on commit 7115a31

Please sign in to comment.