mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-19 16:13:42 +02:00
RoomContextualMenuViewController: Handle updated ReactionsMenuView and new animations instructions.
This commit is contained in:
@@ -18,12 +18,18 @@ import UIKit
|
||||
|
||||
@objc protocol RoomContextualMenuViewControllerDelegate: class {
|
||||
func roomContextualMenuViewControllerDidTapBackgroundOverlay(_ viewController: RoomContextualMenuViewController)
|
||||
func roomContextualMenuViewControllerDidReaction(_ viewController: RoomContextualMenuViewController)
|
||||
}
|
||||
|
||||
@objcMembers
|
||||
final class RoomContextualMenuViewController: UIViewController, Themable {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
private enum Constants {
|
||||
static let reactionsMenuViewVerticalMargin: CGFloat = 10.0
|
||||
static let reactionsMenuViewHiddenScale: CGFloat = 0.97
|
||||
}
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Outlets
|
||||
@@ -34,15 +40,20 @@ final class RoomContextualMenuViewController: UIViewController, Themable {
|
||||
@IBOutlet private weak var menuToolbarViewHeightConstraint: NSLayoutConstraint!
|
||||
@IBOutlet private weak var menuToolbarViewBottomConstraint: NSLayoutConstraint!
|
||||
|
||||
@IBOutlet private weak var reactionsMenuView: ReactionsMenuView!
|
||||
@IBOutlet private weak var reactionsMenuContainerView: UIView!
|
||||
@IBOutlet private weak var reactionsMenuViewHeightConstraint: NSLayoutConstraint!
|
||||
@IBOutlet private weak var reactionsMenuViewBottomConstraint: NSLayoutConstraint!
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private var theme: Theme!
|
||||
private var errorPresenter: MXKErrorPresentation!
|
||||
private var contextualMenuItems: [RoomContextualMenuItem] = []
|
||||
private var contextualMenuItems: [RoomContextualMenuItem] = []
|
||||
private var reactionsMenuViewModel: ReactionsMenuViewModel?
|
||||
|
||||
private weak var reactionsMenuView: ReactionsMenuView?
|
||||
|
||||
private var reactionsMenuViewBottomStartConstraintConstant: CGFloat?
|
||||
private var reactionsMenuViewBottomEndConstraintConstant: CGFloat?
|
||||
|
||||
private var hiddenToolbarViewBottomConstant: CGFloat {
|
||||
let bottomSafeAreaHeight: CGFloat
|
||||
@@ -58,30 +69,40 @@ final class RoomContextualMenuViewController: UIViewController, Themable {
|
||||
|
||||
// MARK: Public
|
||||
|
||||
var contentToReactFrame: CGRect?
|
||||
var shouldPerformTappedReactionAnimation: Bool {
|
||||
return self.reactionsMenuView?.reactionHasBeenTapped ?? false
|
||||
}
|
||||
|
||||
weak var delegate: RoomContextualMenuViewControllerDelegate?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
class func instantiate(with contextualMenuItems: [RoomContextualMenuItem]) -> RoomContextualMenuViewController {
|
||||
class func instantiate(with contextualMenuItems: [RoomContextualMenuItem],
|
||||
reactionsMenuViewModel: ReactionsMenuViewModel?) -> RoomContextualMenuViewController {
|
||||
let viewController = StoryboardScene.RoomContextualMenuViewController.initialScene.instantiate()
|
||||
viewController.theme = ThemeService.shared().theme
|
||||
viewController.contextualMenuItems = contextualMenuItems
|
||||
viewController.reactionsMenuViewModel = reactionsMenuViewModel
|
||||
return viewController
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Life cycle
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// Do any additional setup after loading the view.
|
||||
self.reactionsMenuView.isHidden = true
|
||||
self.reactionsMenuContainerView.isHidden = true
|
||||
|
||||
if let reactionsMenuViewModel = self.reactionsMenuViewModel {
|
||||
self.setupReactionsMenu(with: reactionsMenuViewModel)
|
||||
}
|
||||
|
||||
self.backgroundOverlayView.isUserInteractionEnabled = true
|
||||
self.menuToolbarView.fill(contextualMenuItems: self.contextualMenuItems)
|
||||
self.setupBackgroundOverlayGestureRecognizers()
|
||||
|
||||
self.errorPresenter = MXKErrorAlertPresentation()
|
||||
|
||||
self.registerThemeServiceDidChangeThemeNotification()
|
||||
self.update(theme: self.theme)
|
||||
@@ -91,31 +112,87 @@ final class RoomContextualMenuViewController: UIViewController, Themable {
|
||||
|
||||
func showMenuToolbar() {
|
||||
self.menuToolbarViewBottomConstraint.constant = 0
|
||||
self.menuToolbarView.alpha = 1
|
||||
}
|
||||
|
||||
func hideMenuToolbar() {
|
||||
self.menuToolbarViewBottomConstraint.constant = self.hiddenToolbarViewBottomConstant
|
||||
self.menuToolbarView.alpha = 0
|
||||
}
|
||||
|
||||
func showReactionsMenu(withViewModel viewModel: ReactionsMenuViewModel, aroundFrame frame: CGRect) {
|
||||
self.reactionsMenuView.viewModel = viewModel
|
||||
self.reactionsMenuView.isHidden = false
|
||||
|
||||
|
||||
func prepareReactionsMenuAnimations() {
|
||||
guard let frame = self.contentToReactFrame else {
|
||||
return
|
||||
}
|
||||
|
||||
let menuHeight = self.reactionsMenuViewHeightConstraint.constant
|
||||
|
||||
let verticalMargin = Constants.reactionsMenuViewVerticalMargin
|
||||
|
||||
let reactionsMenuViewBottomStartConstraintConstant: CGFloat?
|
||||
let reactionsMenuViewBottomEndConstraintConstant: CGFloat?
|
||||
|
||||
// Try to display the menu at the top of the message first
|
||||
// Then, try at the bottom
|
||||
// Else, keep the position defined in the storyboard
|
||||
if frame.origin.y >= self.reactionsMenuViewHeightConstraint.constant {
|
||||
self.reactionsMenuViewBottomConstraint.constant = frame.origin.y
|
||||
if frame.origin.y - verticalMargin >= menuHeight {
|
||||
let menuViewBottomY = frame.origin.y - verticalMargin
|
||||
reactionsMenuViewBottomStartConstraintConstant = menuViewBottomY + menuHeight/2
|
||||
reactionsMenuViewBottomEndConstraintConstant = menuViewBottomY
|
||||
} else {
|
||||
let frameBottomY = frame.origin.y + frame.size.height
|
||||
let frameBottomY = frame.origin.y + frame.size.height + verticalMargin
|
||||
let visibleViewHeight = self.view.frame.size.height - self.menuToolbarView.frame.size.height
|
||||
|
||||
|
||||
if frameBottomY + menuHeight < visibleViewHeight {
|
||||
self.reactionsMenuViewBottomConstraint.constant = frameBottomY + menuHeight
|
||||
let menuViewBottomY = frameBottomY + menuHeight
|
||||
|
||||
reactionsMenuViewBottomEndConstraintConstant = menuViewBottomY
|
||||
reactionsMenuViewBottomStartConstraintConstant = menuViewBottomY - menuHeight/2
|
||||
} else {
|
||||
reactionsMenuViewBottomEndConstraintConstant = nil
|
||||
reactionsMenuViewBottomStartConstraintConstant = nil
|
||||
}
|
||||
}
|
||||
|
||||
self.reactionsMenuViewBottomStartConstraintConstant = reactionsMenuViewBottomStartConstraintConstant
|
||||
self.reactionsMenuViewBottomEndConstraintConstant = reactionsMenuViewBottomEndConstraintConstant
|
||||
|
||||
self.reactionsMenuContainerView.isHidden = false
|
||||
}
|
||||
|
||||
func showReactionsMenu() {
|
||||
guard let reactionsMenuView = self.reactionsMenuView else {
|
||||
return
|
||||
}
|
||||
|
||||
if let reactionsMenuViewBottomEndConstraintConstant = self.reactionsMenuViewBottomEndConstraintConstant {
|
||||
self.reactionsMenuViewBottomConstraint.constant = reactionsMenuViewBottomEndConstraintConstant
|
||||
}
|
||||
|
||||
reactionsMenuView.alpha = 1
|
||||
reactionsMenuContainerView.transform = CGAffineTransform.identity
|
||||
}
|
||||
|
||||
func hideReactionsMenu() {
|
||||
guard let reactionsMenuView = self.reactionsMenuView else {
|
||||
return
|
||||
}
|
||||
|
||||
if let reactionsMenuViewBottomStartConstraintConstant = self.reactionsMenuViewBottomStartConstraintConstant {
|
||||
self.reactionsMenuViewBottomConstraint.constant = reactionsMenuViewBottomStartConstraintConstant
|
||||
}
|
||||
|
||||
reactionsMenuView.alpha = 0
|
||||
|
||||
let transformScale = Constants.reactionsMenuViewHiddenScale
|
||||
self.reactionsMenuContainerView.transform = CGAffineTransform(scaleX: transformScale, y: transformScale)
|
||||
}
|
||||
|
||||
func selectedReactionAnimationsIntructionsPart1() {
|
||||
self.reactionsMenuView?.selectionAnimationInstructionPart1()
|
||||
}
|
||||
|
||||
func selectedReactionAnimationsIntructionsPart2() {
|
||||
self.reactionsMenuView?.selectionAnimationInstructionPart2()
|
||||
}
|
||||
|
||||
func update(theme: Theme) {
|
||||
@@ -124,6 +201,13 @@ final class RoomContextualMenuViewController: UIViewController, Themable {
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func setupReactionsMenu(with viewModel: ReactionsMenuViewModel) {
|
||||
let reactionsMenuView = ReactionsMenuView.loadFromNib()
|
||||
self.reactionsMenuContainerView.vc_addSubViewMatchingParent(reactionsMenuView)
|
||||
reactionsMenuView.viewModel = viewModel
|
||||
self.reactionsMenuView = reactionsMenuView
|
||||
}
|
||||
|
||||
private func setupBackgroundOverlayGestureRecognizers() {
|
||||
|
||||
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handle(gestureRecognizer:)))
|
||||
@@ -155,6 +239,6 @@ extension RoomContextualMenuViewController: UIGestureRecognizerDelegate {
|
||||
|
||||
// Avoid triggering background overlay gesture recognizers when touching reactions menu
|
||||
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
|
||||
return touch.vc_isInside(view: self.reactionsMenuView) == false
|
||||
return touch.vc_isInside(view: self.reactionsMenuContainerView) == false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user