2022-05-10 15:05:56 +03:00
|
|
|
//
|
2024-09-06 16:34:30 +03:00
|
|
|
// Copyright 2022-2024 New Vector Ltd.
|
2022-05-10 15:05:56 +03:00
|
|
|
//
|
2025-01-06 11:27:37 +01:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
|
|
// Please see LICENSE files in the repository root for full details.
|
2022-05-10 15:05:56 +03:00
|
|
|
//
|
|
|
|
|
2023-12-19 12:12:16 +01:00
|
|
|
// periphery:ignore:all - this is just a template remove this comment once generating the final file
|
|
|
|
|
2023-04-05 17:07:12 +02:00
|
|
|
import Combine
|
2022-05-10 15:05:56 +03:00
|
|
|
import SwiftUI
|
|
|
|
|
2023-08-02 13:24:57 +03:00
|
|
|
struct TemplateScreenCoordinatorParameters { }
|
2022-05-10 15:05:56 +03:00
|
|
|
|
2023-04-24 15:03:46 +01:00
|
|
|
enum TemplateScreenCoordinatorAction {
|
2023-08-02 13:24:57 +03:00
|
|
|
case done
|
2023-01-17 09:28:01 +00:00
|
|
|
|
|
|
|
// Consider adding CustomStringConvertible conformance if the actions contain PII
|
2022-05-26 16:04:48 +03:00
|
|
|
}
|
|
|
|
|
2023-04-24 15:03:46 +01:00
|
|
|
final class TemplateScreenCoordinator: CoordinatorProtocol {
|
|
|
|
private let parameters: TemplateScreenCoordinatorParameters
|
2024-02-28 13:21:54 +02:00
|
|
|
private let viewModel: TemplateScreenViewModelProtocol
|
2022-05-10 15:05:56 +03:00
|
|
|
|
2024-02-28 13:21:54 +02:00
|
|
|
private var cancellables = Set<AnyCancellable>()
|
|
|
|
|
|
|
|
private let actionsSubject: PassthroughSubject<TemplateScreenCoordinatorAction, Never> = .init()
|
|
|
|
var actionsPublisher: AnyPublisher<TemplateScreenCoordinatorAction, Never> {
|
2023-04-05 17:07:12 +02:00
|
|
|
actionsSubject.eraseToAnyPublisher()
|
|
|
|
}
|
2022-05-10 15:05:56 +03:00
|
|
|
|
2023-04-24 15:03:46 +01:00
|
|
|
init(parameters: TemplateScreenCoordinatorParameters) {
|
2022-05-10 15:05:56 +03:00
|
|
|
self.parameters = parameters
|
|
|
|
|
2023-08-02 13:24:57 +03:00
|
|
|
viewModel = TemplateScreenViewModel()
|
2022-05-10 15:05:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func start() {
|
2024-02-28 13:21:54 +02:00
|
|
|
viewModel.actionsPublisher.sink { [weak self] action in
|
2023-08-02 13:24:57 +03:00
|
|
|
MXLog.info("Coordinator: received view model action: \(action)")
|
|
|
|
|
2022-10-17 09:56:17 +01:00
|
|
|
guard let self else { return }
|
2022-05-26 16:04:48 +03:00
|
|
|
switch action {
|
2023-08-02 13:24:57 +03:00
|
|
|
case .done:
|
2024-09-17 20:08:35 +01:00
|
|
|
actionsSubject.send(.done)
|
2022-05-26 16:04:48 +03:00
|
|
|
}
|
2022-05-10 15:05:56 +03:00
|
|
|
}
|
2023-04-05 17:07:12 +02:00
|
|
|
.store(in: &cancellables)
|
2022-05-10 15:05:56 +03:00
|
|
|
}
|
2022-11-16 15:37:34 +02:00
|
|
|
|
|
|
|
func toPresentable() -> AnyView {
|
|
|
|
AnyView(TemplateScreen(context: viewModel.context))
|
2022-05-10 15:05:56 +03:00
|
|
|
}
|
|
|
|
}
|