Skip to main content

Link Preview

Overview

The LMChatMessageLinkPreview is used to display link previews within chat message. It shows a thumbnail image, title, and description of the linked content.

UI Components

  • containerView: An LMView that serves as the main container for the preview.
  • containerStackView: An LMStackView that organizes the image and metadata vertically.
  • imageView: An LMImageView that displays the link's thumbnail.
  • metaDataContainerView: An LMView that holds the metadata stack view.
  • metaDataStackView: An LMStackView that organizes the title and description labels.
  • titleLabel: An LMLabel that displays the link's title.
  • descriptionLabel: An LMLabel that shows the link's description.

Methods

  • setData(_ data: ContentModel): Updates the preview's appearance based on the provided data.
  • onLinkClicked(_ gesture: UITapGestureRecognizer): Handles tap events on the preview.

Customization

CustomChatMessageLinkPreview.swift
class CustomChatMessageLinkPreview: LMChatMessageLinkPreview {
override func setupViews() {
super.setupViews()
// Add custom view setup here
}

override func setData(_ data: ContentModel) {
super.setData(data)
// Add custom data handling here
}
}
AppDelegate.swift
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
// Register custom link preview class if needed
LMUIComponents.shared.messageLinkPreview = CustomChatMessageLinkPreview.self
// ...
return true
}