Create Short Video
Overview
The Create Short Video Screen (LMFeedCreateShortVideoScreen
) provides an interface for creating and editing short-form video content. It allows users to add video content, write descriptions, and mention other users in their posts.
File Location:
LMFeedCreateShortVideoScreen.swift
Functionality
Protocols Implemented
LMFeedCreateShortVideoViewModelProtocol
Defines methods that are triggered from the view model and are implemented by the view controller using it
showVideo(video: [LMFeedMediaProtocol])
: Called when video data is available to be displayed. Updates the video preview with the provided video data.resetMediaView()
: Called to clear and reset the video preview view to its initial state.
LMFeedTaggingTextViewProtocol
Defines methods that are triggered from the tagging text view and are implemented by the view controller using it
mentionStarted(with text: String)
: Called when a user starts typing a mention (using '@'). Shows the tagging view and initiates user search.mentionStopped()
: Called when a user stops typing a mention. Hides the tagging view and stops user search.contentHeightChanged()
: Called when the content height of the text view changes. Updates the create button state.
LMFeedTaggedUserFoundProtocol
Defines methods that are triggered when a user is selected from the tagging list
userSelected(with route: String, and userName: String)
: Called when a user is selected from the tagging list. Adds the selected user to the text view.updateHeight(with height: CGFloat)
: Called to update the height of the tagging view based on its content.
UI Components
containerStackView
: A vertical stack view containing the scroll view and add media stack.scrollView
: A scroll view that contains the post creation elements.scrollStackView
: A vertical stack view within the scroll view for content organization.inputTextView
: A text view for entering post content with user mention support.videoPreview
: A collection view for displaying video content.createPostButton
: A button for submitting the video post.taggingView
: A view for displaying and selecting mentioned users.
Data Variables
videoAttachmentData
: An array ofLMFeedMediaProtocol
objects containing video data.videoCollectionViewHeightConstraint
: A constraint for the video preview's height.taggingViewHeight
: A constraint for the tagging view's height.
Methods
setupViews()
: Configures the initial view hierarchy.setupLayouts()
: Sets up the layout constraints for all UI components.setupActions()
: Configures action handlers for UI elements.setupInitialView()
: Initializes the view state.observeCreateButton()
: Updates the create button's enabled state based on content.
Action Handlers
didTapCreateButton()
: Called when the create post button is tapped.
Customization
CustomCreateShortVideoScreen.swift
class CustomCreateShortVideoScreen: LMFeedCreateShortVideoScreen {
override func setupAppearance() {
super.setupAppearance()
containerView.backgroundColor = .systemBackground
inputTextView.backgroundColor = .secondarySystemBackground
}
}
AppDelegate.swift
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
Components.shared.createShortVideoScreen = CustomCreateShortVideoScreen.self
// ...
return true
}