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 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
}
}