Document Preview
Overview
LMFeedDocumentPreview
represents a preview of a document attachment. It displays the document's title, icon, size, page count, and type, along with an optional cross button for removing the document.
Protocols
LMFeedDocumentPreviewProtocol
This protocol defines methods for handling user interactions with the document preview:
didTapCrossButton(documentID:)
: Called when the cross button is tapped, passing the document URL as a parameter.didTapDocument(documentID:)
: Called when the document preview itself is tapped, passing the document URL as a parameter.
UI Components
containerView
: The main container view that holds all other subviews.outerStackView
: A horizontalLMStackView
that arranges the document icon, label container, and cross button.documentIcon
: AnLMImageView
that displays the document icon.labelContainerView
: A container view that holds the label stack view.labelStackView
: A verticalLMStackView
that arranges the title and subtitle labels.titleLabel
: AnLMLabel
that displays the document's title.subtitleLabel
: AnLMLabel
that displays the document's size, page count, and type.crossButton
: AnLMButton
that represents the cross button for removing the document.
Data Variables
delegate
: A weak reference to an instance conforming toLMFeedDocumentPreviewProtocol
for handling user interactions.documentID
: An optionalURL
object representing the document's URL.
Methods
configure()
: Configures the document preview with the providedContentModel
data and sets thedelegate
.
Action Handlers
didTapCrossButton()
: The selector method for the cross button's tap action. It checks if thedocumentID
is set and notifies thedelegate
to handle the event.didTapDocumentCell()
: The selector method for the tap gesture recognizer on the container view. It checks if thedocumentID
is set and notifies thedelegate
to handle the event.
Customization
CustomDocumentPreview.swift
class CustomDocumentPreview: LMFeedDocumentPreview {
override func setupAppearance() {
super.setupAppearance()
containerView.backgroundColor = .green
titleLabel.textColor = .white
}
}
AppDelegate.swift
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
LMUIComponents.shared.documentPreview = CustomDocumentPreview.self
// ...
return true
}