Media Preview
Overview
The LMFeedMediaPreviewScreen
displays media content such as images and videos in a scrollable collection view. It allows users to view media items with paging functionality.
Protocols
LMMediaViewModelDelegate
This protocol defines methods for updating the media preview and navigation data:
showImages(with media: [LMFeedMediaPreviewContentModel], userName: String, date: String):
Displays the media items along with user details.scrollToIndex(index: Int):
Scrolls to a specific media item.setNavigationData(index: Int):
Updates the navigation title and subtitle based on the current media index.
UI Components
mediaCollectionView:
A collection view displaying the media items.layout:
The layout configuration for the collection view, defining item and group sizes.
Data Variables
viewModel:
The view model managing the media preview data and interactions.mediaData:
An array ofLMFeedMediaPreviewContentModel
containing media items.userName:
The name of the user associated with the media.date:
The date when the media was created.
Methods
setupViews():
Adds the collection view to the main view.setupLayouts():
Sets the constraints for the collection view.viewDidLoad():
Calls the view model to show media preview.viewDidAppear(_ animated: Bool):
Calls the view model to scroll to the media preview.
Action Handlers
collectionView(_:numberOfItemsInSection:):
Returns the number of media items in the collection view.collectionView(_:cellForItemAt:):
Configures and returns the appropriate cell for the media item.
Customization
To create a custom media preview screen, follow these steps:
Step 1: Create a Custom Media Preview Screen
// CustomMediaPreviewScreen.swift
class CustomMediaPreviewScreen: LMFeedMediaPreviewScreen {
override func setupAppearance() {
super.setupAppearance()
view.backgroundColor = .lightGray
}
}
Step 2: Replace the Default Screen in the Components Class
In AppDelegate.swift
, update the Components.shared.mediaPreviewScreen
to use the custom screen class:
// AppDelegate.swift
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
Components.shared.mediaPreviewScreen = CustomMediaPreviewScreen.self
// ...
return true
}