49 lines
1.4 KiB
Swift
49 lines
1.4 KiB
Swift
import SwiftUI
|
|
import UIKit
|
|
|
|
struct AttachmentFilesPickerView: View {
|
|
@State private var isPickerPresented = false
|
|
|
|
var body: some View {
|
|
Button(action: {
|
|
isPickerPresented = true
|
|
}) {
|
|
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
|
|
}
|
|
}
|
|
}
|