Skip to content

Commit

Permalink
feat: Add optional "custom data" field to YPMediaItem
Browse files Browse the repository at this point in the history
  • Loading branch information
iirovi-rs committed Apr 30, 2024
1 parent 7efadbc commit d35c945
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions Source/Filters/Video/YPVideoFiltersVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ open class YPVideoFiltersVC: UIViewController, IsMediaFilterVC {
let resultVideo = YPMediaVideo(thumbnail: thumbnail, videoURL: videoUrl, asset: asset)
resultVideo.cropRect = inputVideo.cropRect
resultVideo.timeRange = timeRange
resultVideo.customData = inputVideo.customData
didSave(YPMediaItem.video(v: resultVideo))
setupRightBarButtonItem()

Expand Down
19 changes: 17 additions & 2 deletions Source/Models/YPMediaItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ public class YPMediaPhoto {
public var url: URL?
public var cropRect: CGRect?

public var customData: [String: Any]?

public init(image: UIImage,
exifMeta: [String: Any]? = nil,
fromCamera: Bool = false,
asset: PHAsset? = nil,
url: URL? = nil) {
url: URL? = nil,
customData: [String: Any]? = nil) {
self.originalImage = image
self.modifiedImage = nil
self.fromCamera = fromCamera
self.exifMeta = exifMeta
self.asset = asset
self.url = url
self.customData = customData
}
}

Expand All @@ -52,12 +56,16 @@ public class YPMediaVideo {
public var timeRange: CMTimeRange?
public var cropRect: CGRect?

public init(thumbnail: UIImage, videoURL: URL, fromCamera: Bool = false, asset: PHAsset? = nil) {

public var customData: [String: Any]?

public init(thumbnail: UIImage, videoURL: URL, fromCamera: Bool = false, asset: PHAsset? = nil, customData: [String: Any]? = nil) {
self.originalThumbnail = thumbnail
self.selectedThumbnail = thumbnail
self.originalUrl = videoURL
self.fromCamera = fromCamera
self.asset = asset
self.customData = customData
}
}

Expand Down Expand Up @@ -101,6 +109,13 @@ public enum YPMediaItem {
case .video(let video): video.cropRect
}
}

public var customData: [String: Any]? {
switch self {
case .photo(let photo): photo.customData
case .video(let video): video.customData
}
}
}

// MARK: - Compression
Expand Down

0 comments on commit d35c945

Please sign in to comment.