Skip to main content

Attachment Gallery#

AttachmentGalleryActivity is an Activity used to display attachments that the users have sent in the chat. It is an image gallery where users can view, share, and download the pictures, and use a menu to easily navigate through them.

Light ModeDark Mode
attachment_gallery_example1_lightattachment_gallery_example1_dark
attachment_gallery_example2_lightattachment_gallery_example2_dark

Handling Actions#

There are four user actions that can be customized by the following handlers:

  • AttachmentReplyOptionHandler
  • AttachmentShowInChatOptionHandler
  • AttachmentDownloadOptionHandler
  • AttachmentDeleteOptionHandler

These are called when the user selects one of the options from the overflow menu in the top right:

LightDark
attachment_gallery_example2_lightattachment_gallery_example2_light

As the gallery is usually opened from MessageListView, you can set these handlers on that View the following way:

messageListView.setAttachmentReplyOptionClickHandler { resultItem ->    resultItem.messageId    // Handle reply to attachment}
messageListView.setAttachmentShowInChatOptionClickHandler { resultItem ->    resultItem.messageId    // Handle show in chat}
messageListView.setDownloadOptionHandler { resultItem ->    resultItem.assetUrl    // Handle download the attachment}
messageListView.setAttachmentDeleteOptionClickHandler { resultItem ->    resultItem.assetUrl    resultItem.imageUrl    // Handle delete}

Navigating To Attachment Gallery#

By default, the Attachment Gallery is opened when a user clicks on an attachment in MessageListView. In that case, all actions mentioned above have a default implementation, which can be changed by overriding MessageListView's handlers.

You can also navigate to AttachmentGalleryActivity manually from anywhere else in your code. In this case, you will need to implement all available actions:

// Create Attachment Gallery Destinationval destination = AttachmentGalleryDestination(    requireContext(),    attachmentReplyOptionHandler = { resultItem ->        // Handle reply    },    attachmentShowInChatOptionHandler = { resultItem ->        // Handle show image in chat    },    attachmentDownloadOptionHandler = { resultItem ->        // Handle download image    },    attachmentDeleteOptionClickHandler = { resultItem ->        // Handle delete image    },)
// Register destination with the ActivityResultRegistryactivity?.activityResultRegistry?.let { registry ->    destination.register(registry)}
// Set the data to displaydestination.setData(attachmentGalleryItems = listOf(), attachmentIndex = 0)
// Fire the navigation requestChatUI.instance().navigator.navigate(destination)

Did you find this page helpful?