2022-02-17 11:10:55 +00:00
|
|
|
//
|
|
|
|
// Copyright 2021 New Vector Ltd
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import CommonKit
|
|
|
|
import UIKit
|
|
|
|
|
2022-02-22 15:26:51 +00:00
|
|
|
/// Presenter which displays fullscreen loading spinners, and conforming to legacy `ActivityIndicatorPresenterType`,
|
|
|
|
/// but interally wrapping an `UserIndicatorPresenter` which is used in conjuction with `UserIndicator` and `UserIndicatorQueue`.
|
2022-02-17 11:10:55 +00:00
|
|
|
///
|
2022-02-22 16:21:11 +00:00
|
|
|
/// Note: clients can skip using `FullscreenActivityIndicatorPresenter` and instead coordinate with `AppNavigatorProtocol` directly.
|
2022-02-17 11:10:55 +00:00
|
|
|
/// The presenter exists mostly as a transition for view controllers already using `ActivityIndicatorPresenterType` and / or view controllers
|
|
|
|
/// written in objective-c.
|
|
|
|
@objc final class FullscreenActivityIndicatorPresenter: NSObject, ActivityIndicatorPresenterType {
|
|
|
|
private let label: String
|
|
|
|
private weak var viewController: UIViewController?
|
2022-02-22 15:26:51 +00:00
|
|
|
private var indicator: UserIndicator?
|
2022-02-17 11:10:55 +00:00
|
|
|
|
|
|
|
init(label: String, on viewController: UIViewController) {
|
|
|
|
self.label = label
|
|
|
|
self.viewController = viewController
|
|
|
|
}
|
|
|
|
|
|
|
|
func presentActivityIndicator(on view: UIView, animated: Bool, completion: (() -> Void)?) {
|
|
|
|
guard let vc = viewController else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-02-22 15:26:51 +00:00
|
|
|
let request = UserIndicatorRequest(
|
|
|
|
presenter: FullscreenLoadingIndicatorPresenter(label: label, on: vc),
|
2022-02-17 11:10:55 +00:00
|
|
|
dismissal: .manual
|
|
|
|
)
|
|
|
|
|
2022-02-22 15:26:51 +00:00
|
|
|
indicator = UserIndicatorQueue.shared.add(request)
|
2022-02-17 11:10:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@objc func removeCurrentActivityIndicator(animated: Bool, completion: (() -> Void)?) {
|
2022-02-22 15:26:51 +00:00
|
|
|
indicator?.cancel()
|
2022-02-17 11:10:55 +00:00
|
|
|
}
|
|
|
|
}
|