Beam/Tools/Scripts/Templates/SimpleScreenExample/ElementX/TemplateScreenCoordinator.swift
manuroe 3950cac085
Dual licensing: AGPL + Element Commercial (#3657)
* New LICENSE-COMMERCIAL file

* Apply dual licenses: AGPL + Element Commercial to file headers

* Update README with dual licensing
2025-01-06 11:27:37 +01:00

55 lines
1.6 KiB
Swift

//
// Copyright 2022-2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
// periphery:ignore:all - this is just a template remove this comment once generating the final file
import Combine
import SwiftUI
struct TemplateScreenCoordinatorParameters { }
enum TemplateScreenCoordinatorAction {
case done
// Consider adding CustomStringConvertible conformance if the actions contain PII
}
final class TemplateScreenCoordinator: CoordinatorProtocol {
private let parameters: TemplateScreenCoordinatorParameters
private let viewModel: TemplateScreenViewModelProtocol
private var cancellables = Set<AnyCancellable>()
private let actionsSubject: PassthroughSubject<TemplateScreenCoordinatorAction, Never> = .init()
var actionsPublisher: AnyPublisher<TemplateScreenCoordinatorAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(parameters: TemplateScreenCoordinatorParameters) {
self.parameters = parameters
viewModel = TemplateScreenViewModel()
}
func start() {
viewModel.actionsPublisher.sink { [weak self] action in
MXLog.info("Coordinator: received view model action: \(action)")
guard let self else { return }
switch action {
case .done:
actionsSubject.send(.done)
}
}
.store(in: &cancellables)
}
func toPresentable() -> AnyView {
AnyView(TemplateScreen(context: viewModel.context))
}
}