ContextMenu glitching on message longpress

This is happening when adding a ContextMenuInteraction to the SBUUserMessageCell. Did you encounter this before?

We need a different design for the delete/edit/copy message functionality, is there a better way to customise the one in the SDK?

Thanks!

Hello @Victor_Riurean , Welcome to the Sendbird Community.

I guess it’s because the menu item position is calculated internally. Can you access to mainContainer of the message cell? I think the context menu is adjusted to the entire message cell.

Also, you can refer to our sample app. Our sample app has the below design for the delete/edit/copy that might help.


image (3)

Hello Chinmaya.

Thank you for taking the time to help.

I would need to customise the appearance of this and I would also need a preview of the message. Is that possible? If so, could you please provide me with a link in the docs where I can find information on customising this?

Thanks!

P.S. just to clarify, my issue when it comes to the ContextMenu is not that the preview is missing, it is with the glitches that happen before the menu is shown.

Hi @Victor_Riurean Currently, UIKit doesn’t support the context menu officially. You can try like below:

let interaction = UIContextMenuInteraction(delegate: self)
messageCell.mainContainer.addInteraction(interaction) // just code snippet, please use appropriate view instead of messageCell.mainContainer

...

func contextMenuInteraction(_ interaction: UIContextMenuInteraction,
                            configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
// please refer to `createMenuItems` in `SBUBaseChannelViewController` 
    return UIContextMenuConfiguration(identifier: nil,
                                      previewProvider: nil,
                                      actionProvider: {
            suggestedActions in
        let copyAction =
            UIAction(title: NSLocalizedString("Copy", comment: ""),
                     image: {Copy image}) { action in
                    guard let userMessage = message as? SBDUserMessage else { return }
                    
                    let pasteboard = UIPasteboard.general
                    pasteboard.string = userMessage.message
            }
            
        let editAction =
            UIAction(title: NSLocalizedString("Edit", comment: ""),
                     image: {Edit image}) { action in
                if self.baseChannel?.isFrozen == false {
                        self.messageInputView.setMode(.edit, message: userMessage)
                    } else {
                        SBULog.info("This channel is frozen")
                    }
            }
            
        let deleteAction =
            UIAction(title: NSLocalizedString("Delete", comment: ""),
                     image: {Delete image},
                     attributes: .destructive) { action in
                guard let self = self else { return }
                    guard message.threadInfo.replyCount == 0 else { return }
                    self.deleteMessage(message: message)
            }
                                        
        return UIMenu(title: "", children: [copyAction, editAction, deleteAction])
    })
}

Normally, you should be able to see the message preview when the context menu is shown. However, that functionality is not officially supported with the UIKit. Also, our team is planning for UIKit 3.0 and there you will see some changes but no ETA for the same.

You need to customize this based on your use case. There is an apple docs regarding on it: Apple Developer Documentation

See if this helps.

Hello Chinmaya,

thanks again for helping with this.

Just to clarify, my issue is with the glitch that is happening before the context menu is shown. Do you know what could be causing it?

Thank you very much!

LE: the glitch gets even worse when the cell preview is added to the contextMenu and the screen seems to be split in half(?!). Do you have any thoughts on this?