Skip to main content

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.

LMFeedPostLinkCell

File Location:
LMFeedDocumentPreview.swift

Functionality

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: A LMFeedView main container view that holds all other subviews.
  • outerStackView: A horizontal LMFeedStackView` that arranges the document icon, label container, and cross button.
  • documentIcon: An LMFeedImageView that displays the document icon.
  • labelContainerView: A LMFeedView container view that holds the label stack view.
  • labelStackView: A vertical LMFeedStackView that arranges the title and subtitle labels.
  • titleLabel: An LMFeedLabel that displays the document's title.
  • subtitleLabel: An LMFeedLabel that displays the document's size, page count, and type.
  • crossButton: An LMFeedButton that represents the cross button for removing the document.

Data Variables

  • delegate: A weak reference to an instance conforming to LMFeedDocumentPreviewProtocol for handling user interactions.
  • documentID: An optional URL object representing the document's URL.

Methods

  • configure(): Configures the document preview with the provided ContentModel data and sets the delegate.

Action Handlers

  • didTapCrossButton(): The selector method for the cross button's tap action. It checks if the documentID is set and notifies the delegate to handle the event.

  • didTapDocumentCell(): The selector method for the tap gesture recognizer on the container view. It checks if the documentID is set and notifies the delegate 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
}