2026-02-09 19:49:55 +00:00
|
|
|
#if canImport(UIKit)
|
|
|
|
|
import SwiftUI
|
|
|
|
|
import UniformTypeIdentifiers
|
|
|
|
|
import UIKit
|
|
|
|
|
|
2026-03-09 16:47:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/// MARK: - Types
|
|
|
|
|
|
2026-02-09 19:49:55 +00:00
|
|
|
struct ProjectFolderPicker: UIViewControllerRepresentable {
|
|
|
|
|
let onPick: (URL) -> Void
|
|
|
|
|
let onCancel: () -> Void
|
|
|
|
|
|
|
|
|
|
func makeCoordinator() -> Coordinator {
|
|
|
|
|
Coordinator(onPick: onPick, onCancel: onCancel)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func makeUIViewController(context: Context) -> UIDocumentPickerViewController {
|
|
|
|
|
let picker = UIDocumentPickerViewController(forOpeningContentTypes: [.folder], asCopy: false)
|
|
|
|
|
picker.allowsMultipleSelection = false
|
|
|
|
|
picker.delegate = context.coordinator
|
|
|
|
|
return picker
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func updateUIViewController(_ uiViewController: UIDocumentPickerViewController, context: Context) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final class Coordinator: NSObject, UIDocumentPickerDelegate {
|
|
|
|
|
private let onPick: (URL) -> Void
|
|
|
|
|
private let onCancel: () -> Void
|
|
|
|
|
|
|
|
|
|
init(onPick: @escaping (URL) -> Void, onCancel: @escaping () -> Void) {
|
|
|
|
|
self.onPick = onPick
|
|
|
|
|
self.onCancel = onCancel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
|
|
|
|
|
onCancel()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
|
|
|
|
|
if let url = urls.first {
|
|
|
|
|
onPick(url)
|
|
|
|
|
} else {
|
|
|
|
|
onCancel()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|