mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-26 19:34:25 +02:00
Introduce ThreadsBetaCoordinator & open thread view directly after enabling threads
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
// File created from FlowTemplate
|
||||
// $ createRootCoordinator.sh Threads ThreadsBeta
|
||||
/*
|
||||
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 UIKit
|
||||
|
||||
@objcMembers
|
||||
final class ThreadsBetaCoordinator: NSObject, ThreadsBetaCoordinatorProtocol {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private let threadId: String
|
||||
private lazy var viewController: ThreadsBetaViewController = {
|
||||
let result = ThreadsBetaViewController.instantiate()
|
||||
result.didTapEnableButton = { [weak self] in
|
||||
guard let self = self else { return }
|
||||
self.delegate?.threadsBetaCoordinatorDidTapEnable(self)
|
||||
}
|
||||
result.didTapCancelButton = { [weak self] in
|
||||
guard let self = self else { return }
|
||||
self.delegate?.threadsBetaCoordinatorDidTapCancel(self)
|
||||
}
|
||||
return result
|
||||
}()
|
||||
|
||||
// MARK: Public
|
||||
|
||||
// Must be used only internally
|
||||
var childCoordinators: [Coordinator] = []
|
||||
|
||||
weak var delegate: ThreadsBetaCoordinatorDelegate?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(threadId: String) {
|
||||
self.threadId = threadId
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
func start() {
|
||||
// no-op. this is a static screen
|
||||
}
|
||||
|
||||
func toPresentable() -> UIViewController {
|
||||
return viewController
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
// File created from FlowTemplate
|
||||
// $ createRootCoordinator.sh Threads ThreadsBeta
|
||||
/*
|
||||
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 MatrixSDK
|
||||
|
||||
@objc protocol ThreadsBetaCoordinatorBridgePresenterDelegate {
|
||||
func threadsBetaCoordinatorBridgePresenterDelegateDidTapEnable(_ coordinatorBridgePresenter: ThreadsBetaCoordinatorBridgePresenter)
|
||||
func threadsBetaCoordinatorBridgePresenterDelegateDidTapCancel(_ coordinatorBridgePresenter: ThreadsBetaCoordinatorBridgePresenter)
|
||||
}
|
||||
|
||||
/// ThreadsBetaCoordinatorBridgePresenter enables to start ThreadsBetaCoordinator from a view controller.
|
||||
/// This bridge is used while waiting for global usage of coordinator pattern.
|
||||
/// **WARNING**: This class breaks the Coordinator abstraction and it has been introduced for **Objective-C compatibility only** (mainly for integration in legacy view controllers). Each bridge should be removed once the underlying Coordinator has been integrated by another Coordinator.
|
||||
@objcMembers
|
||||
final class ThreadsBetaCoordinatorBridgePresenter: NSObject {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
public let threadId: String
|
||||
private let slidingModalPresenter = SlidingModalPresenter()
|
||||
private var coordinator: ThreadsBetaCoordinator?
|
||||
|
||||
// MARK: Public
|
||||
|
||||
weak var delegate: ThreadsBetaCoordinatorBridgePresenterDelegate?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(threadId: String) {
|
||||
self.threadId = threadId
|
||||
super.init()
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
func present(from viewController: UIViewController, animated: Bool) {
|
||||
|
||||
let threadsBetaCoordinator = ThreadsBetaCoordinator(threadId: threadId)
|
||||
threadsBetaCoordinator.delegate = self
|
||||
guard let presentable = threadsBetaCoordinator.toPresentable() as? SlidingModalPresentable.ViewControllerType else {
|
||||
MXLog.error("[ThreadsBetaCoordinatorBridgePresenter] Presentable is not 'SlidingModalPresentable'")
|
||||
return
|
||||
}
|
||||
slidingModalPresenter.present(presentable,
|
||||
from: viewController,
|
||||
animated: animated,
|
||||
options: .spanning,
|
||||
completion: nil)
|
||||
threadsBetaCoordinator.start()
|
||||
|
||||
self.coordinator = threadsBetaCoordinator
|
||||
}
|
||||
|
||||
func dismiss(animated: Bool, completion: (() -> Void)?) {
|
||||
slidingModalPresenter.dismiss(animated: animated, completion: completion)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - ThreadsBetaCoordinatorDelegate
|
||||
extension ThreadsBetaCoordinatorBridgePresenter: ThreadsBetaCoordinatorDelegate {
|
||||
|
||||
func threadsBetaCoordinatorDidTapEnable(_ coordinator: ThreadsBetaCoordinatorProtocol) {
|
||||
self.delegate?.threadsBetaCoordinatorBridgePresenterDelegateDidTapEnable(self)
|
||||
}
|
||||
|
||||
func threadsBetaCoordinatorDidTapCancel(_ coordinator: ThreadsBetaCoordinatorProtocol) {
|
||||
self.delegate?.threadsBetaCoordinatorBridgePresenterDelegateDidTapCancel(self)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// File created from FlowTemplate
|
||||
// $ createRootCoordinator.sh Threads ThreadsBeta
|
||||
/*
|
||||
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
|
||||
|
||||
protocol ThreadsBetaCoordinatorDelegate: AnyObject {
|
||||
func threadsBetaCoordinatorDidTapEnable(_ coordinator: ThreadsBetaCoordinatorProtocol)
|
||||
func threadsBetaCoordinatorDidTapCancel(_ coordinator: ThreadsBetaCoordinatorProtocol)
|
||||
}
|
||||
|
||||
/// `ThreadsBetaCoordinatorProtocol` is a protocol describing a Coordinator that handle xxxxxxx navigation flow.
|
||||
protocol ThreadsBetaCoordinatorProtocol: Coordinator, Presentable {
|
||||
var delegate: ThreadsBetaCoordinatorDelegate? { get }
|
||||
}
|
||||
Reference in New Issue
Block a user