Skip to main content

Chat Message Reply Preview

Overview

The LMChatMessageReplyPreview is a custom view component designed to display a preview of a message being replied to.

Functionality

Protocols

LMBottomMessageReplyPreviewDelegate

  • func clearReplyPreview(): method for clearing the reply preview.

UI Components

  • containerView: The main container for the reply preview.
  • sidePannelColorView: A colored view indicating the reply status.
  • userNameLabel: Displays the name of the original message sender.
  • messageLabel: Shows the content of the original message.
  • messageAttachmentImageView: Displays a thumbnail of any attached media.
  • closeReplyButton: Allows users to dismiss the reply preview.
  • horizontalReplyStackView: Organizes the reply content horizontally.
  • verticleUsernameAndMessageContainerStackView: Arranges the username and message vertically.

Properties

  • delegate: A weak reference to an object conforming to LMBottomMessageReplyPreviewDelegate.
  • viewData: Stores the ContentModel for the current reply preview.
  • onClickReplyPreview: A closure that can be set to handle taps on the reply preview.
  • onClickCancelReplyPreview: A closure that can be set to handle cancellation of the reply.

Methods

  • setData(_:): Populates the view with data from a ContentModel.
  • setDataForEdit(_:): Configures the view for editing an existing message.
  • createAttributedString(_:): Creates an attributed string for the message content, including icons for different attachment types.
  • cancelReply(_:): Handles the cancellation of the reply preview.
  • onReplyPreviewClicked(_:): Handles taps on the reply preview.

Customization

CustomChatMessageReplyPreview.swift
class CustomChatMessageReplyPreview: LMChatMessageReplyPreview {
override func setupAppearance() {
super.setupAppearance()
containerView.backgroundColor = .lightGray
}

override func createAttributedString(_ data: ContentModel) -> NSAttributedString {
// Custom implementation for creating attributed string
}
}
AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
LMUIComponents.shared.messageReplyView = CustomChatMessageReplyPreview.self
// ...
return true
}