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
: AnLMView
that serves as the main container for the preview.containerStackView
: AnLMStackView
that organizes the image and metadata vertically.imageView
: AnLMImageView
that displays the link's thumbnail.metaDataContainerView
: AnLMView
that holds the metadata stack view.metaDataStackView
: AnLMStackView
that organizes the title and description labels.titleLabel
: AnLMLabel
that displays the link's title.descriptionLabel
: AnLMLabel
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
}