element-ios/Riot/Modules/SecureBackup/Setup/SecureBackupSetupCoordinatorBridgePresenter.swift

89 lines
3.3 KiB
Swift
Raw Normal View History

// File created from FlowTemplate
// $ createRootCoordinator.sh KeyBackupSetup/SecureSetup SecureKeyBackupSetup
/*
Copyright 2020 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
2020-06-26 12:01:33 +00:00
@objc protocol SecureBackupSetupCoordinatorBridgePresenterDelegate {
func secureBackupSetupCoordinatorBridgePresenterDelegateDidComplete(_ coordinatorBridgePresenter: SecureBackupSetupCoordinatorBridgePresenter)
2020-06-26 12:11:58 +00:00
func secureBackupSetupCoordinatorBridgePresenterDelegateDidCancel(_ coordinatorBridgePresenter: SecureBackupSetupCoordinatorBridgePresenter)
}
2020-06-26 12:11:58 +00:00
/// SecureBackupSetupCoordinatorBridgePresenter enables to start SecureBackupSetupCoordinator from a view controller.
/// This bridge is used while waiting for global usage of coordinator pattern.
@objcMembers
2020-06-26 12:01:33 +00:00
final class SecureBackupSetupCoordinatorBridgePresenter: NSObject {
// MARK: - Properties
// MARK: Private
private let session: MXSession
2020-06-26 12:01:33 +00:00
private var coordinator: SecureBackupSetupCoordinator?
// MARK: Public
2020-06-26 12:01:33 +00:00
weak var delegate: SecureBackupSetupCoordinatorBridgePresenterDelegate?
// MARK: - Setup
init(session: MXSession) {
self.session = session
super.init()
}
// MARK: - Public
// NOTE: Default value feature is not compatible with Objective-C.
// func present(from viewController: UIViewController, animated: Bool) {
// self.present(from: viewController, animated: animated)
// }
func present(from viewController: UIViewController, animated: Bool) {
2020-06-26 12:11:58 +00:00
let secureBackupSetupCoordinator = SecureBackupSetupCoordinator(session: self.session)
secureBackupSetupCoordinator.delegate = self
viewController.present(secureBackupSetupCoordinator.toPresentable(), animated: animated, completion: nil)
secureBackupSetupCoordinator.start()
2020-06-26 12:11:58 +00:00
self.coordinator = secureBackupSetupCoordinator
}
func dismiss(animated: Bool, completion: (() -> Void)?) {
guard let coordinator = self.coordinator else {
return
}
coordinator.toPresentable().dismiss(animated: animated) {
self.coordinator = nil
if let completion = completion {
completion()
}
}
}
}
2020-06-26 12:11:58 +00:00
// MARK: - SecureBackupSetupCoordinatorDelegate
2020-06-26 12:01:33 +00:00
extension SecureBackupSetupCoordinatorBridgePresenter: SecureBackupSetupCoordinatorDelegate {
func secureBackupSetupCoordinatorDidComplete(_ coordinator: SecureBackupSetupCoordinatorType) {
self.delegate?.secureBackupSetupCoordinatorBridgePresenterDelegateDidComplete(self)
}
2020-06-26 12:01:33 +00:00
func secureBackupSetupCoordinatorDidCancel(_ coordinator: SecureBackupSetupCoordinatorType) {
2020-06-26 12:11:58 +00:00
self.delegate?.secureBackupSetupCoordinatorBridgePresenterDelegateDidCancel(self)
}
}