mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Improve media uploading content type selection. Fix pasting in screenshots not working
This commit is contained in:
committed by
Stefan Ceriu
parent
ba02c439dd
commit
061e66ff57
@@ -15,12 +15,30 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
extension NSItemProvider {
|
||||
var isSupportedForPasteOrDrop: Bool {
|
||||
!registeredContentTypes
|
||||
.compactMap(\.preferredMIMEType)
|
||||
.filter { $0.hasPrefix("image/") || $0.hasPrefix("video/") || $0.hasPrefix("application/") }
|
||||
.isEmpty
|
||||
preferredContentType != nil
|
||||
}
|
||||
|
||||
var preferredContentType: UTType? {
|
||||
let supportedContentTypes = registeredContentTypes
|
||||
.filter { isMimeTypeSupported($0.preferredMIMEType) }
|
||||
|
||||
// Have .jpeg take priority over .heic
|
||||
if supportedContentTypes.contains(.jpeg) {
|
||||
return .jpeg
|
||||
}
|
||||
|
||||
return supportedContentTypes.first
|
||||
}
|
||||
|
||||
private func isMimeTypeSupported(_ mimeType: String?) -> Bool {
|
||||
guard let mimeType else {
|
||||
return false
|
||||
}
|
||||
|
||||
return mimeType.hasPrefix("image/") || mimeType.hasPrefix("video/") || mimeType.hasPrefix("application/")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user