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.
File Location:
LMChatMessageDocumentPreview.swift
Functionality
Protocols
LMChatMessageDocumentPreviewDelegate
- `onClickAttachment(_ url: String): triggered when the document is tapped on.
UI Components
outerStackView: A vertical LMStackView that contains all other UI elements.previewImage: An LMImageView for displaying a preview image of the document (currently unused).containerView: An LMView that holds the document icon and details.innerStackView: A vertical LMStackView for organizing document details.sampleImage: An LMImageView displaying the document type icon.titleLabel: An LMLabel showing the document's file name.subtitleLabel: An LMLabel displaying additional document details (pages, size, type).
Properties
delegate: A weak reference to an object conforming toLMChatMessageDocumentPreviewDelegate.viewData: Stores theContentModeldata 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
}