Text Cell
Overview
LMFeedPostTextCell
is a subclass of LMPostWidgetTableViewCell designed to display text-based posts in the LikeMinds Feed module. This cell is responsible for presenting the post’s title and body text. It includes a "See More" button that appears when the content exceeds a certain length. The layout is managed using Auto Layout to ensure proper arrangement and sizing of subviews according to the content.
Protocols
LMFeedPostTextCellDelegate
Conforms to LMPostWidgetTableViewCellDelegate
. It includes functions for handling interactions within the text cell:
didTapPost(postID: String)
: Invoked when the user taps on the post content.didTapURL(url: URL)
: Called when a URL in the text is tapped.didTapRoute(route: String)
: Called when a route in the text is tapped.didTapSeeMoreButton(for postID: String)
: Called when the "See More" button is tapped.
UI Components
questionTitle
: AnLMLabel
displaying the title of the post.postText
: AnLMTextView
that shows the body text of the post. It supports rich text attributes and handles user interactions such as tapping on URLs or hashtags.seeMoreButton
: AnLMButton
that shows additional content when the post text exceeds a certain length.
Data Variables
actionDelegate
: A weak reference to an instance conforming toLMFeedPostTextCellDelegate
for handling user interactions.postID
: An optionalString
that stores the identifier of the post.
Methods
configure(data: LMFeedPostContentModel)
: Configures the cell with the provided post data. Sets the title, body text, and configures the visibility of the "See More" button based on the content length.tappedTextView(tapGesture: UITapGestureRecognizer)
: Handles taps on the text view. Determines if a URL, hashtag, route, or post content was tapped and notifies the delegate accordingly.didTapURL(url: URL)
: Called when a URL is tapped in the text view.didTapHashTag(hashtag: String)
: Placeholder for handling hashtag taps (currently does nothing).didTapRoute(route: String)
: Called when a route is tapped in the text view.didTapSeeMoreButton()
: Called when the "See More" button is tapped. Notifies the delegate to handle the event.
Action Handlers
didTapSeeMoreButton()
: The selector method for the "See More" button's tap action. It checks if thepostID
is set and notifies the delegate to handle the event.
Customisation
To create a custom cell for LMFeedPostTextCell
, follow these steps:
Step 1: Create a Custom Text Cell
CustomTextCell.swift
class CustomTextCell: LMFeedPostTextCell {
override func setupAppearance() {
super.setupAppearance()
contentView.backgroundColor = .lightGray
questionTitle.font = UIFont.boldSystemFont(ofSize: 18)
}
}
Step 2: Replace the Default Cell in the UI Components Class
In AppDelegate.swift
, update the LMUIComponents.shared.textCell
to use the custom cell class:
AppDelegate.swift
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
LMUIComponents.shared.textCell = CustomTextCell.self
// ...
return true
}