mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-03-28 12:35:27 +00:00
Fix pasting image from clipboard on iOS + reduce JPEG further
This commit is contained in:
parent
2610b7c747
commit
2b2d042085
2 changed files with 23 additions and 1 deletions
|
@ -59,6 +59,8 @@ enum StatusEditorUTTypeSupported: String, CaseIterable {
|
|||
} else if let data = result as? Data,
|
||||
let image = UIImage(data: data) {
|
||||
return image
|
||||
} else if let transferable = await getImageTansferable(item: item){
|
||||
return transferable
|
||||
}
|
||||
}
|
||||
if let url = result as? URL {
|
||||
|
@ -97,6 +99,19 @@ enum StatusEditorUTTypeSupported: String, CaseIterable {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func getImageTansferable(item: NSItemProvider) async -> ImageFileTranseferable? {
|
||||
return await withCheckedContinuation { continuation in
|
||||
_ = item.loadTransferable(type: ImageFileTranseferable.self) { result in
|
||||
switch result {
|
||||
case let .success(success):
|
||||
continuation.resume(with: .success(success))
|
||||
case .failure:
|
||||
continuation.resume(with: .success(nil))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct MovieFileTranseferable: Transferable {
|
||||
|
@ -133,7 +148,7 @@ struct ImageFileTranseferable: Transferable {
|
|||
let url: URL
|
||||
|
||||
lazy var data: Data? = try? Data(contentsOf: url)
|
||||
lazy var compressedData: Data? = image?.jpegData(compressionQuality: 0.90)
|
||||
lazy var compressedData: Data? = image?.jpegData(compressionQuality: 0.80)
|
||||
lazy var image: UIImage? = UIImage(data: data ?? Data())
|
||||
|
||||
static var transferRepresentation: some TransferRepresentation {
|
||||
|
|
|
@ -370,6 +370,13 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
|
|||
gifTransferable: nil,
|
||||
mediaAttachment: nil,
|
||||
error: nil))
|
||||
} else if var content = content as? ImageFileTranseferable,
|
||||
let image = content.image {
|
||||
mediasImages.append(.init(image: image,
|
||||
movieTransferable: nil,
|
||||
gifTransferable: nil,
|
||||
mediaAttachment: nil,
|
||||
error: nil))
|
||||
} else if let video = content as? MovieFileTranseferable {
|
||||
mediasImages.append(.init(image: nil,
|
||||
movieTransferable: video,
|
||||
|
|
Loading…
Reference in a new issue