Document Preview
Overview
The LMChatMessageDocumentPreview
is a custom view class designed to display a preview of document attachments. It provides a visual representation of various document types, including file name, size, number of pages, and file type.
Functionality
Protocols
LMChatMessageDocumentPreviewDelegate
- `onClickAttachment(_ url: String): triggered when the document is tapped on.
UI Components
outerStackView
: A verticalLMStackView
that contains all other UI elements.previewImage
: AnLMImageView
for displaying a preview image of the document (currently unused).containerView
: AnLMView
that holds the document icon and details.innerStackView
: A verticalLMStackView
for organizing document details.sampleImage
: AnLMImageView
displaying the document type icon.titleLabel
: AnLMLabel
showing the document's file name.subtitleLabel
: AnLMLabel
displaying additional document details (pages, size, type).
Properties
delegate
: A weak reference to an object conforming toLMChatMessageDocumentPreviewDelegate
.viewData
: Stores theContentModel
data used to populate the view.
Methods
setupViews()
: Configures the initial view hierarchy and appearance.setupLayouts()
: Sets up auto layout constraints for the UI components.setData(_:)
: Populates the view with data from aContentModel
.onAttachmentClicked(_:)
: Handles tap gestures on the document preview.
Customization
CustomDocumentPreview.swift
class CustomDocumentPreview: LMChatMessageDocumentPreview {
override func setupViews() {
super.setupViews()
// Add custom views or modify existing ones
}
override func setData(_ data: ContentModel) {
super.setData(data)
// Customize how data is displayed
}
override func onAttachmentClicked(_ gesture: UITapGestureRecognizer) {
super.onAttachmentClicked(gesture)
// Add custom behavior when the attachment is clicked
}
}
AppDelegate.swift
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
LMUIComponents.shared.messageDocumentPreview = CustomDocumentPreview.self
// ...
return true
}