Add loading indicators to the SwiftUI templates. (#6014)

This commit is contained in:
Doug
2022-04-11 12:57:58 +01:00
committed by GitHub
parent 5e7f78a1fa
commit 9339889fd6
3 changed files with 45 additions and 0 deletions
@@ -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
}
}