another.im-ios/ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift

64 lines
2 KiB
Swift
Raw Normal View History

2024-07-02 09:56:27 +00:00
import SwiftUI
import UIKit
struct AttachmentFilesPickerView: View {
2024-07-10 13:00:54 +00:00
@EnvironmentObject var store: AppStore
2024-07-02 09:56:27 +00:00
var body: some View {
2024-07-10 13:00:54 +00:00
DocumentPicker(
completion: { arr in
let sharedFiles = arr.map {
ShareItem(
id: UUID().uuidString,
type: .file,
data: $0,
thumbnail: Data(),
string: ""
)
}
store.dispatch(.conversationAction(.sendAttachment(sharedFiles)))
store.dispatch(.conversationAction(.showAttachmentPicker(false)))
},
cancel: {
store.dispatch(.conversationAction(.showAttachmentPicker(false)))
}
)
2024-07-02 09:56:27 +00:00
}
}
struct DocumentPicker: UIViewControllerRepresentable {
2024-07-10 13:00:54 +00:00
let completion: ([Data]) -> Void
let cancel: () -> Void
2024-07-02 09:56:27 +00:00
func makeUIViewController(context: UIViewControllerRepresentableContext<DocumentPicker>) -> UIDocumentPickerViewController {
2024-07-04 11:45:39 +00:00
let picker: UIDocumentPickerViewController
picker = UIDocumentPickerViewController(forOpeningContentTypes: [.item], asCopy: true)
2024-07-02 09:56:27 +00:00
picker.delegate = context.coordinator
picker.allowsMultipleSelection = true
return picker
}
func updateUIViewController(_: UIDocumentPickerViewController, context _: UIViewControllerRepresentableContext<DocumentPicker>) {}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
class Coordinator: NSObject, UIDocumentPickerDelegate {
var parent: DocumentPicker
init(_ parent: DocumentPicker) {
self.parent = parent
}
func documentPicker(_: UIDocumentPickerViewController, didPickDocumentsAt _: [URL]) {
2024-07-04 11:45:39 +00:00
// TODO: Send documents
2024-07-02 09:56:27 +00:00
// Handle the selected files
}
func documentPickerWasCancelled(_: UIDocumentPickerViewController) {
2024-07-10 13:00:54 +00:00
parent.cancel()
2024-07-02 09:56:27 +00:00
}
}
}