Skip to content

Added copy support for message bubble#422

Merged
zhongwuzw merged 3 commits into
developmentfrom
feature/cell-copy
Jan 11, 2018
Merged

Added copy support for message bubble#422
zhongwuzw merged 3 commits into
developmentfrom
feature/cell-copy

Conversation

@zhongwuzw

Copy link
Copy Markdown
Member

@zhongwuzw zhongwuzw requested a review from SD10 December 22, 2017 15:36

@nathantannar4 nathantannar4 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runs smooth!

let selectedIndexPath = selectedIndexPathForMenu {
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIMenuControllerWillShowMenu, object: nil)
defer {
NotificationCenter.default.addObserver(self, selector: #selector(MessagesViewController.menuControllerWillShow(aNotification:)), name: NSNotification.Name.UIMenuControllerWillShowMenu, object: nil)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question, why do we keep adding ab observer here? It looks like we never remove it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nathantannar4 , emm, we need remove here first, because we call currentMenuController.setMenuVisible(true, animated: true) later, it would leads to endless loop if we not remove in advance.

@nathantannar4

Copy link
Copy Markdown
Member

@zhongwuzw i mean why add the observer

Sent with GitHawk

@zhongwuzw

Copy link
Copy Markdown
Member Author

@nathantannar4 , we need customize the target rect to bubble, default would target rect to cell.
I remove observer at here.

NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIMenuControllerWillShowMenu, object: nil)

@SD10

SD10 commented Dec 23, 2017

Copy link
Copy Markdown
Member

Thanks for doing this @zhongwuzw! It will take me some time to be able to review it

}

/// Show menuController and set target rect to selected bubble
@objc func menuControllerWillShow(aNotification:Notification) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhongwuzw Can we just name this parameter notification? And add a space after the colon

Comment thread CHANGELOG.md Outdated
- Added `configureAvatarView(_ avatarView: AvatarView, for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView)` method in `MessagesDisplayDelegate` `protocol` to configure `avatarView`.
[#416](https://github.com/MessageKit/MessageKit/pull/416) by [@zhongwuzw](https://github.com/zhongwuzw).

- Added copy support for message bubble.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Added copy support for image, text, and emoji messages".

This would sound better. Sorry!

extension MessagesViewController {
/// Add observer for `UIMenuControllerWillShowMenu` notification
fileprivate func addMenuControllerObservers() {
NotificationCenter.default.addObserver(self, selector: #selector(MessagesViewController.menuControllerWillShow(aNotification:)), name: NSNotification.Name.UIMenuControllerWillShowMenu, object: nil)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the shorthand version of the notification names please .UIMenuControllerWillShowMenu?

/// Handle long press gesture, return true when gestureRecognizer's touch point in `messageContainerView`'s frame
open override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
let touchPoint = gestureRecognizer.location(in: self)
if gestureRecognizer.isKind(of: UILongPressGestureRecognizer.self) {

@SD10 SD10 Jan 7, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this?

guard gestureRecognizer.isKind(of: UILongPressGestureRecognizer.self) else { return false }
return messageContainerView.frame.contains(touchPoint)

@SD10

SD10 commented Jan 7, 2018

Copy link
Copy Markdown
Member

@zhongwuzw Think there is any way to prevent the menu from appearing outside the content view?
screen shot 2018-01-06 at 11 18 57 pm

What about adding support for copying the image from AvatarView?

@zhongwuzw

Copy link
Copy Markdown
Member Author

Think there is any way to prevent the menu from appearing outside the content view?

@SD10 , good question, another problem, what if message's height exceed the screen height?where should we position menu at?

@SD10

SD10 commented Jan 8, 2018

Copy link
Copy Markdown
Member

good question, another problem, what if message's height exceed the screen height?where should we position menu at?

@zhongwuzw I think we should position it at the bottom of the message. It may work like that already.

@zhongwuzw

Copy link
Copy Markdown
Member Author

@SD10 , I updated the code to handle some situations, like situation below, menu would be blocked by keyboard, JSQMessagesViewController still has this issue.
menu-example

@SD10 SD10 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhongwuzw If the menu is covered by the keyboard in JSQMessagesViewController then we can merge this for now. Let's open an issue to track this behavior?

@zhongwuzw zhongwuzw merged commit e05912b into development Jan 11, 2018
@zhongwuzw zhongwuzw deleted the feature/cell-copy branch January 11, 2018 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants