Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Copy Action #1814

Open
confusionhill opened this issue Sep 8, 2023 · 2 comments
Open

On Copy Action #1814

confusionhill opened this issue Sep 8, 2023 · 2 comments
Labels

Comments

@confusionhill
Copy link

Hello, I wanted to know if there's a delegate to detect on copy ? i wanted to debug to check why the image isn't copied

Thanks

@fukemy
Copy link

fukemy commented Sep 15, 2023

no, you must handle by your self

@ohserezha
Copy link

yes. there are three handler functions inside MessagesViewController

open func collectionView(_: UICollectionView, shouldShowMenuForItemAt indexPath: IndexPath) -> Bool {
   guard let messagesDataSource = messagesCollectionView.messagesDataSource else { return false }

   if isSectionReservedForTypingIndicator(indexPath.section) {
     return false
   }

   let message = messagesDataSource.messageForItem(at: indexPath, in: messagesCollectionView)

   switch message.kind {
   case .text, .attributedText, .emoji, .photo:
     selectedIndexPathForMenu = indexPath
     return true
   default:
     return false
   }
 }

 open func collectionView(
   _: UICollectionView,
   canPerformAction action: Selector,
   forItemAt indexPath: IndexPath,
   withSender _: Any?)
   -> Bool
 {
   if isSectionReservedForTypingIndicator(indexPath.section) {
     return false
   }
   return (action == NSSelectorFromString("copy:"))
 }

 open func collectionView(_: UICollectionView, performAction _: Selector, forItemAt indexPath: IndexPath, withSender _: Any?) {
   guard let messagesDataSource = messagesCollectionView.messagesDataSource else {
     fatalError(MessageKitError.nilMessagesDataSource)
   }
   let pasteBoard = UIPasteboard.general
   let message = messagesDataSource.messageForItem(at: indexPath, in: messagesCollectionView)

   switch message.kind {
   case .text(let text), .emoji(let text):
     pasteBoard.string = text
   case .attributedText(let attributedText):
     pasteBoard.string = attributedText.string
   case .photo(let mediaItem):
     pasteBoard.image = mediaItem.image ?? mediaItem.placeholderImage
   default:
     break
   }
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants