RoomVC: ContextualMenu: Plug reactions menu

This commit is contained in:
manuroe
2019-05-17 12:10:32 +02:00
parent 7782fde16f
commit 57e7505044
4 changed files with 87 additions and 1 deletions
@@ -102,4 +102,10 @@ final class RoomContextualMenuPresenter: NSObject {
animationCompletionInstructions()
}
}
func showReactionsMenu(forEvent eventId: String, inRoom roomId: String, session: MXSession,
aroundFrame frame: CGRect) {
let reactionsMenuViewModel = ReactionsMenuViewModel(aggregations: session.aggregations, roomId: roomId, eventId: eventId)
self.roomContextualMenuViewController?.showReactionsMenu(withViewModel: reactionsMenuViewModel, aroundFrame: frame)
}
}
@@ -20,7 +20,21 @@
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Szx-Dr-Ndt">
<rect key="frame" x="0.0" y="0.0" width="414" height="793"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Vdy-rp-3g9" customClass="ReactionsMenuView" customModule="Riot" customModuleProvider="target">
<rect key="frame" x="0.0" y="100" width="414" height="100"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="100" id="D3i-aE-kdL"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="Vdy-rp-3g9" firstAttribute="bottom" secondItem="Szx-Dr-Ndt" secondAttribute="top" constant="200" id="0GH-Qk-vKA"/>
<constraint firstAttribute="trailing" secondItem="Vdy-rp-3g9" secondAttribute="trailing" id="9Gu-dr-IPv"/>
<constraint firstItem="Vdy-rp-3g9" firstAttribute="leading" secondItem="Szx-Dr-Ndt" secondAttribute="leading" id="h78-sP-xDx"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="0GC-JU-rI3" customClass="RoomContextualMenuToolbarView" customModule="Riot" customModuleProvider="target">
<rect key="frame" x="0.0" y="793" width="414" height="69"/>
@@ -47,6 +61,9 @@
<outlet property="menuToolbarView" destination="0GC-JU-rI3" id="j0z-I8-Pcr"/>
<outlet property="menuToolbarViewBottomConstraint" destination="s4i-80-0iu" id="E5w-5m-m5O"/>
<outlet property="menuToolbarViewHeightConstraint" destination="ynL-KP-iB4" id="Zeb-b0-Yil"/>
<outlet property="reactionsMenuView" destination="Vdy-rp-3g9" id="jJT-mz-vg6"/>
<outlet property="reactionsMenuViewBottomConstraint" destination="0GH-Qk-vKA" id="8lg-XL-JgW"/>
<outlet property="reactionsMenuViewHeightConstraint" destination="D3i-aE-kdL" id="CCr-hW-2dv"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="8NV-wl-Hp0" userLabel="First Responder" sceneMemberID="firstResponder"/>
@@ -18,6 +18,7 @@ import UIKit
@objc protocol RoomContextualMenuViewControllerDelegate: class {
func roomContextualMenuViewControllerDidTapBackgroundOverlay(_ viewController: RoomContextualMenuViewController)
func roomContextualMenuViewControllerDidReaction(_ viewController: RoomContextualMenuViewController)
}
@objcMembers
@@ -33,9 +34,14 @@ 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 reactionsMenuViewHeightConstraint: NSLayoutConstraint!
@IBOutlet private weak var reactionsMenuViewBottomConstraint: NSLayoutConstraint!
// MARK: Private
private var theme: Theme!
private var errorPresenter: MXKErrorPresentation!
private var contextualMenuItems: [RoomContextualMenuItem] = []
private var hiddenToolbarViewBottomConstant: CGFloat {
@@ -69,10 +75,13 @@ final class RoomContextualMenuViewController: UIViewController, Themable {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.reactionsMenuView.isHidden = true
self.backgroundOverlayView.isUserInteractionEnabled = true
self.menuToolbarView.fill(contextualMenuItems: self.contextualMenuItems)
self.setupBackgroundOverlayTapGestureRecognizer()
self.errorPresenter = MXKErrorAlertPresentation()
self.registerThemeServiceDidChangeThemeNotification()
self.update(theme: self.theme)
@@ -87,6 +96,28 @@ final class RoomContextualMenuViewController: UIViewController, Themable {
func hideMenuToolbar() {
self.menuToolbarViewBottomConstraint.constant = self.hiddenToolbarViewBottomConstant
}
func showReactionsMenu(withViewModel viewModel: ReactionsMenuViewModel, aroundFrame frame: CGRect) {
self.reactionsMenuView.viewModel = viewModel
self.reactionsMenuView.viewModel?.coordinatorDelegate = self
self.reactionsMenuView.isHidden = false
let menuHeight = self.reactionsMenuViewHeightConstraint.constant
// 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
} else {
let frameBottomY = frame.origin.y + frame.size.height
let visibleViewHeight = self.view.frame.size.height - self.menuToolbarView.frame.size.height
if frameBottomY + menuHeight < visibleViewHeight {
self.reactionsMenuViewBottomConstraint.constant = frameBottomY + menuHeight
}
}
}
func update(theme: Theme) {
self.menuToolbarView.update(theme: theme)
@@ -111,3 +142,18 @@ final class RoomContextualMenuViewController: UIViewController, Themable {
self.update(theme: ThemeService.shared().theme)
}
}
extension RoomContextualMenuViewController: ReactionsMenuViewModelCoordinatorDelegate {
func reactionsMenuViewModel(_ viewModel: ReactionsMenuViewModelType, didSendReaction reaction: String, isAddReaction: Bool) {
self.delegate?.roomContextualMenuViewControllerDidReaction(self)
}
func reactionsMenuViewModel(_ viewModel: ReactionsMenuViewModelType, didReactionComplete reaction: String, isAddReaction: Bool) {
}
func reactionsMenuViewModel(_ viewModel: ReactionsMenuViewModelType, didReactionFailedWithError error: Error, reaction: String, isAddReaction: Bool) {
self.errorPresenter?.presentError(from: self, forError: error, animated: true) {
}
}
}