mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-23 01:52:44 +02:00
[Spaces] Space menu #4494
- First implementation of the space contextual menu
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
/// Presenter for spaces contextual menu
|
||||
class SpaceMenuPresenter: NSObject {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private weak var presentingViewController: UIViewController?
|
||||
private let viewModel = SpaceMenuViewModel()
|
||||
private weak var sourceView: UIView?
|
||||
private lazy var slidingModalPresenter: SlidingModalPresenter = {
|
||||
return SlidingModalPresenter()
|
||||
}()
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
func present(forSpaceWithId spaceId: String,
|
||||
from viewController: UIViewController,
|
||||
sourceView: UIView?,
|
||||
session: MXSession,
|
||||
animated: Bool) {
|
||||
|
||||
self.viewModel.coordinatorDelegate = self
|
||||
self.presentingViewController = viewController
|
||||
self.sourceView = sourceView
|
||||
|
||||
self.showMenu(for: spaceId, session: session)
|
||||
}
|
||||
|
||||
func dismiss(animated: Bool, completion: (() -> Void)?) {
|
||||
self.presentingViewController?.dismiss(animated: animated, completion: completion)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func showMenu(for spaceId: String, session: MXSession) {
|
||||
let menuViewController = SpaceMenuViewController.instantiate(forSpaceWithId: spaceId, matrixSession: session, viewModel: self.viewModel)
|
||||
self.present(menuViewController, animated: true)
|
||||
}
|
||||
|
||||
private func present(_ viewController: SpaceMenuViewController, animated: Bool) {
|
||||
|
||||
// if UIDevice.current.isPhone {
|
||||
guard let rootViewController = self.presentingViewController else {
|
||||
MXLog.error("[SpaceMenuPresenter] present no rootViewController found")
|
||||
return
|
||||
}
|
||||
|
||||
slidingModalPresenter.present(viewController, from: rootViewController.presentedViewController ?? rootViewController, animated: true, completion: nil)
|
||||
// } else {
|
||||
// Configure source view when view controller is presented with a popover
|
||||
// viewController.modalPresentationStyle = .popover
|
||||
// if let sourceView = self.sourceView, let popoverPresentationController = viewController.popoverPresentationController {
|
||||
// popoverPresentationController.sourceView = sourceView
|
||||
// popoverPresentationController.sourceRect = sourceView.bounds
|
||||
// }
|
||||
//
|
||||
// self.presentingViewController?.present(viewController, animated: animated, completion: nil)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - SpaceMenuModelViewModelCoordinatorDelegate
|
||||
|
||||
extension SpaceMenuPresenter: SpaceMenuModelViewModelCoordinatorDelegate {
|
||||
func spaceListViewModelDidDismiss(_ viewModel: SpaceMenuViewModelType) {
|
||||
self.dismiss(animated: true, completion: nil)
|
||||
}
|
||||
|
||||
func spaceListViewModel(_ viewModel: SpaceMenuViewModelType, didSelectItemWithId itemId: String) {
|
||||
self.dismiss(animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user