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

49 lines
1.4 KiB
Swift
Raw Normal View History

2024-07-02 09:56:27 +00:00
import SwiftUI
import UIKit
struct AttachmentFilesPickerView: View {
@State private var isPickerPresented = false
var body: some View {
2024-07-04 08:47:08 +00:00
Button {
2024-07-02 09:56:27 +00:00
isPickerPresented = true
2024-07-04 08:47:08 +00:00
} label: {
2024-07-02 09:56:27 +00:00
Text("Select Files")
}
.sheet(isPresented: $isPickerPresented) {
DocumentPicker()
}
}
}
struct DocumentPicker: UIViewControllerRepresentable {
func makeUIViewController(context: UIViewControllerRepresentableContext<DocumentPicker>) -> UIDocumentPickerViewController {
let picker = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import)
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]) {
// Handle the selected files
}
func documentPickerWasCancelled(_: UIDocumentPickerViewController) {
// Handle cancellation
}
}
}