diff --git a/RiotSwiftUI/Modules/Template/SimpleScreenExample/Coordinator/TemplateSimpleScreenCoordinator.swift b/RiotSwiftUI/Modules/Template/SimpleScreenExample/Coordinator/TemplateSimpleScreenCoordinator.swift index a051f1c57b..f6c92f5d91 100644 --- a/RiotSwiftUI/Modules/Template/SimpleScreenExample/Coordinator/TemplateSimpleScreenCoordinator.swift +++ b/RiotSwiftUI/Modules/Template/SimpleScreenExample/Coordinator/TemplateSimpleScreenCoordinator.swift @@ -15,6 +15,7 @@ // import SwiftUI +import CommonKit struct TemplateSimpleScreenCoordinatorParameters { let promptType: TemplateSimpleScreenPromptType @@ -30,6 +31,9 @@ final class TemplateSimpleScreenCoordinator: Coordinator, Presentable { private let templateSimpleScreenHostingController: UIViewController private var templateSimpleScreenViewModel: TemplateSimpleScreenViewModelProtocol + private var indicatorPresenter: UserIndicatorTypePresenterProtocol + private var loadingIndicator: UserIndicator? + // MARK: Public // Must be used only internally @@ -46,9 +50,12 @@ final class TemplateSimpleScreenCoordinator: Coordinator, Presentable { let view = TemplateSimpleScreen(viewModel: viewModel.context) templateSimpleScreenViewModel = viewModel templateSimpleScreenHostingController = VectorHostingController(rootView: view) + + indicatorPresenter = UserIndicatorTypePresenter(presentingViewController: templateSimpleScreenHostingController) } // MARK: - Public + func start() { MXLog.debug("[TemplateSimpleScreenCoordinator] did start.") templateSimpleScreenViewModel.completion = { [weak self] result in @@ -61,4 +68,19 @@ final class TemplateSimpleScreenCoordinator: Coordinator, Presentable { func toPresentable() -> UIViewController { return self.templateSimpleScreenHostingController } + + // MARK: - Private + + /// Show an activity indicator whilst loading. + /// - Parameters: + /// - label: The label to show on the indicator. + /// - isInteractionBlocking: Whether the indicator should block any user interaction. + private func startLoading(label: String = VectorL10n.loading, isInteractionBlocking: Bool = true) { + loadingIndicator = indicatorPresenter.present(.loading(label: label, isInteractionBlocking: isInteractionBlocking)) + } + + /// Hide the currently displayed activity indicator. + private func stopLoading() { + loadingIndicator = nil + } } diff --git a/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Coordinator/TemplateUserProfileCoordinator.swift b/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Coordinator/TemplateUserProfileCoordinator.swift index f70e6402cd..b541365ed7 100644 --- a/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Coordinator/TemplateUserProfileCoordinator.swift +++ b/RiotSwiftUI/Modules/Template/SimpleUserProfileExample/Coordinator/TemplateUserProfileCoordinator.swift @@ -15,6 +15,7 @@ // import SwiftUI +import CommonKit struct TemplateUserProfileCoordinatorParameters { let session: MXSession @@ -30,6 +31,9 @@ final class TemplateUserProfileCoordinator: Coordinator, Presentable { private let templateUserProfileHostingController: UIViewController private var templateUserProfileViewModel: TemplateUserProfileViewModelProtocol + private var indicatorPresenter: UserIndicatorTypePresenterProtocol + private var loadingIndicator: UserIndicator? + // MARK: Public // Must be used only internally @@ -46,9 +50,12 @@ final class TemplateUserProfileCoordinator: Coordinator, Presentable { .addDependency(AvatarService.instantiate(mediaManager: parameters.session.mediaManager)) templateUserProfileViewModel = viewModel templateUserProfileHostingController = VectorHostingController(rootView: view) + + indicatorPresenter = UserIndicatorTypePresenter(presentingViewController: templateUserProfileHostingController) } // MARK: - Public + func start() { MXLog.debug("[TemplateUserProfileCoordinator] did start.") templateUserProfileViewModel.completion = { [weak self] result in @@ -64,4 +71,19 @@ final class TemplateUserProfileCoordinator: Coordinator, Presentable { func toPresentable() -> UIViewController { return self.templateUserProfileHostingController } + + // MARK: - Private + + /// Show an activity indicator whilst loading. + /// - Parameters: + /// - label: The label to show on the indicator. + /// - isInteractionBlocking: Whether the indicator should block any user interaction. + private func startLoading(label: String = VectorL10n.loading, isInteractionBlocking: Bool = true) { + loadingIndicator = indicatorPresenter.present(.loading(label: label, isInteractionBlocking: isInteractionBlocking)) + } + + /// Hide the currently displayed activity indicator. + private func stopLoading() { + loadingIndicator = nil + } } diff --git a/changelog.d/pr-6014.change b/changelog.d/pr-6014.change new file mode 100644 index 0000000000..000161acb0 --- /dev/null +++ b/changelog.d/pr-6014.change @@ -0,0 +1 @@ +SwiftUI Templates: The coordinators now include a basic implementation of the new UserIndicators.