Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loading indicators to the SwiftUI templates. #6014

Merged
merged 2 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//

import SwiftUI
import CommonKit

struct TemplateSimpleScreenCoordinatorParameters {
let promptType: TemplateSimpleScreenPromptType
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//

import SwiftUI
import CommonKit

struct TemplateUserProfileCoordinatorParameters {
let session: MXSession
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
}
}
1 change: 1 addition & 0 deletions changelog.d/pr-6014.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SwiftUI Templates: The coordinators now include a basic implementation of the new UserIndicators.