Commit d0143172 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Andreas Traczyk

ui: add action copy to message

This patch allows copy message content to a clipboard.

Change-Id: Ifed8efdc605f8f302b3a90276b50217de4287411
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 93629fd8
......@@ -46,4 +46,38 @@ class MessageCell: UITableViewCell, NibReusable {
override func prepareForReuse() {
self.disposeBag = DisposeBag()
}
func showCopyMenu() {
becomeFirstResponder()
let menu = UIMenuController.shared
if !menu.isMenuVisible {
menu.setTargetRect(self.bubble.frame, in: self)
menu.setMenuVisible(true, animated: true)
}
}
func setup() {
let longGestureRecognizer = UILongPressGestureRecognizer()
self.messageLabel.isUserInteractionEnabled = true
self.messageLabel.addGestureRecognizer(longGestureRecognizer)
longGestureRecognizer.rx.event.bind(onNext: { [weak self] _ in
self?.showCopyMenu()
}).disposed(by: self.disposeBag)
}
override func copy(_ sender: Any?) {
UIPasteboard.general.string = self.messageLabel.text
UIMenuController.shared.setMenuVisible(false, animated: true)
}
override var canBecomeFirstResponder: Bool {
return true
}
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == #selector(UIResponderStandardEditActions.copy) {
return true
}
return false
}
}
......@@ -379,6 +379,7 @@ class ConversationViewController: UIViewController, UITextFieldDelegate, Storybo
withMessageVM messageVM: MessageViewModel) {
let type = messageVM.bubblePosition()
let bubbleColor = type == .received ? UIColor.ringMsgCellReceived : UIColor.ringMsgCellSent
cell.setup()
cell.messageLabel.enabledTypes = [.url]
cell.messageLabel.setTextWithLineSpacing(withText: messageVM.content, withLineSpacing: 2)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment