minor ui fix

pull/484/head
Ryan Zhao 4 years ago
parent bb49d7236f
commit 7be6d13afd

@ -66,7 +66,12 @@ extension ContextMenuVC {
}
static func deleteActions(for viewItem: ConversationViewItem, delegate: ContextMenuActionDelegate?) -> [Action] {
return [Action.deleteForEveryone(viewItem, delegate), Action.deleteLocally(viewItem, delegate)]
switch viewItem.interaction.interactionType() {
case .outgoingMessage: return [Action.deleteForEveryone(viewItem, delegate), Action.deleteLocally(viewItem, delegate)]
case .incomingMessage: return [Action.deleteLocally(viewItem, delegate)]
default: return [] // Should never occur
}
}
static func actions(for viewItem: ConversationViewItem, delegate: ContextMenuActionDelegate?) -> [Action] {

@ -75,7 +75,19 @@ final class ContextMenuVC : UIViewController {
} else {
timestampLabel.pin(.left, to: .right, of: snapshot, withInset: Values.smallSpacing)
}
self.updateMenu()
let menuHeight = self.updateMenu()
let spacing = Values.smallSpacing
let margin = max(UIApplication.shared.keyWindow!.safeAreaInsets.bottom, Values.mediumSpacing)
if frame.maxY + spacing + menuHeight > UIScreen.main.bounds.height - margin {
menuView.pin(.bottom, to: .top, of: snapshot, withInset: -spacing)
} else {
menuView.pin(.top, to: .bottom, of: snapshot, withInset: spacing)
}
switch viewItem.interaction.interactionType() {
case .outgoingMessage: menuView.pin(.right, to: .right, of: snapshot)
case .incomingMessage: menuView.pin(.left, to: .left, of: snapshot)
default: break // Should never occur
}
// Tap gesture
let mainTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap))
view.addGestureRecognizer(mainTapGestureRecognizer)
@ -95,7 +107,7 @@ final class ContextMenuVC : UIViewController {
menuView.layer.shadowPath = UIBezierPath(roundedRect: menuView.bounds, cornerRadius: ContextMenuVC.menuCornerRadius).cgPath
}
func updateMenu(forDelete: Bool = false) {
func updateMenu(forDelete: Bool = false) -> CGFloat {
// Menu
menuView.subviews.forEach({ $0.removeFromSuperview() })
let menuBackgroundView = UIView()
@ -111,19 +123,7 @@ final class ContextMenuVC : UIViewController {
menuView.addSubview(menuStackView)
menuStackView.pin(to: menuView)
view.addSubview(menuView)
let menuHeight = CGFloat(actionViews.count) * ContextMenuVC.actionViewHeight
let spacing = Values.smallSpacing
let margin = max(UIApplication.shared.keyWindow!.safeAreaInsets.bottom, Values.mediumSpacing)
if frame.maxY + spacing + menuHeight > UIScreen.main.bounds.height - margin {
menuView.pin(.bottom, to: .top, of: snapshot, withInset: -spacing)
} else {
menuView.pin(.top, to: .bottom, of: snapshot, withInset: spacing)
}
switch viewItem.interaction.interactionType() {
case .outgoingMessage: menuView.pin(.right, to: .right, of: snapshot)
case .incomingMessage: menuView.pin(.left, to: .left, of: snapshot)
default: break // Should never occur
}
return CGFloat(actionViews.count) * ContextMenuVC.actionViewHeight
}
// MARK: Interaction

Loading…
Cancel
Save