Skip to main content

Gallery View

Overview

The LMChatMessageGallaryView is a custom view component responsible for displaying a gallery of images or videos within a chat message. It supports up to four visible items with an overlay for additional items.

Functionality

Protocols

LMChatMessageGallaryViewDelegate

  • onClickAttachment(_ index: Int): Manages user interactions with gallery items.

UI Components

  • singleImage: An ImagePreview instance for displaying a single image.
  • itemSpots: An array of four ImagePreview instances for displaying multiple images.
  • moreItemsOverlay: A LMLabel to indicate additional items beyond the visible ones.
  • previewsContainerView: A LMStackView that contains all preview items.
  • topPreviewsContainerView: A LMStackView for the top row of preview items.
  • bottomPreviewsContainerView: A LMStackView for the bottom row of preview items.

Methods

  • setData(_ data: [ContentModel]): Configures the gallery view with the provided content data.
  • loadImageData(item: ContentModel, imagePreview: ImagePreview): Loads image data into an ImagePreview instance.
  • onAttachmentClicked(_ gesture: UITapGestureRecognizer): Handles tap gestures on gallery items.

Customization

CustomGalleryView.swift
class CustomGalleryView: LMChatMessageGallaryView {
override func setupAppearance() {
super.setupAppearance()
// Customize appearance here
}

override func setupViews() {
super.setupViews()
// Add or modify subviews here
}

override func setupLayouts() {
super.setupLayouts()
// Adjust layouts here
}
}
AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
LMUIComponents.shared.galleryView = CustomGalleryView.self
// ...
return true
}