Document Content View
Overview
The LMChatDocumentContentView is a subclass of LMChatMessageContentView designed to display document attachments. It manages the presentation of document previews, including support for multiple attachments and a "Show More" functionality.
File Location:
LMChatDocumentContentView.swift
Functionality
Protocols Implemented
- LMChatMessageDocumentPreviewDelegate: Handles user interaction with document previews.
UI Components
docPreviewContainerStackView: A vertical LMStackView that contains document preview elements.cancelRetryContainerStackView: A LMStackView for cancel and retry buttons (inherited from superclass).loaderView: ALMAttachmentLoaderViewto display loading state (inherited from superclass).retryView: ALMChatAttachmentUploadRetryViewto display retry option for failed messages (inherited from superclass).
Data Variables
onShowMoreCallback: An optional closure called when the user taps to show more document attachments.
Methods
setDataView(_:index:): Populates the view with data.attachmentView(_:index:): Configures the view based on the document attachments.docPreview(_:): Sets up the preview for document attachments.createDocPreview(_:): Creates a document preview view for a single attachment.prepareToResuse(): Prepares the view for reuse in a table or collection view.didTapShowMore(): Handles the "Show More" action for multiple attachments.updateRetryButton(_:): Updates the visibility of loader and retry views based on message status.
Customization
To customize the LMChatDocumentContentView, you can subclass it and override its methods. Here's an example:
CustomDocumentContentView.swift
class CustomDocumentContentView: LMChatDocumentContentView {
override func setupViews() {
super.setupViews()
// Add custom views or modify existing ones
}
override func attachmentView(_ data: LMChatMessageCell.ContentModel, index: IndexPath) {
super.attachmentView(data, index: index)
// Customize attachment view behavior
}
override func didTapShowMore() {
super.didTapShowMore()
// Add custom behavior when "Show More" is tapped
}
}
To use the custom document content view in your app:
AppDelegate.swift
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
LMUIComponents.shared.documentsContentView = CustomDocumentContentView.self
// ...
return true
}