Allow the mac app to chose room avatars directly from files instead of the photo library

This commit is contained in:
Stefan Ceriu
2026-04-25 11:46:40 +03:00
parent 0ec114d2f3
commit 53a54c1b90
20 changed files with 56 additions and 8 deletions
@@ -7,6 +7,7 @@
//
import SwiftUI
import UniformTypeIdentifiers
enum DocumentPickerAction {
case selectedMediaAtURLs([URL])
@@ -16,19 +17,22 @@ enum DocumentPickerAction {
struct DocumentPicker: UIViewControllerRepresentable {
private let selectionType: MediaPickerScreenSelectionType
private let contentTypes: [UTType]
private let userIndicatorController: UserIndicatorControllerProtocol
private let callback: (DocumentPickerAction) -> Void
init(selectionType: MediaPickerScreenSelectionType,
contentTypes: [UTType],
userIndicatorController: UserIndicatorControllerProtocol,
callback: @escaping (DocumentPickerAction) -> Void) {
self.selectionType = selectionType
self.contentTypes = contentTypes
self.userIndicatorController = userIndicatorController
self.callback = callback
}
func makeUIViewController(context: Context) -> UIDocumentPickerViewController {
let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [.data])
let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: contentTypes)
documentPicker.delegate = context.coordinator
documentPicker.allowsMultipleSelection = switch selectionType {
@@ -7,16 +7,17 @@
//
import SwiftUI
import UniformTypeIdentifiers
struct MediaPickerScreenMode: Hashable {
let source: MediaPickerScreenSource
let selectionType: MediaPickerScreenSelectionType
}
enum MediaPickerScreenSource {
enum MediaPickerScreenSource: Hashable {
case camera
case photoLibrary
case documents
case documents(types: [UTType] = [.data])
}
enum MediaPickerScreenSelectionType {
@@ -79,10 +80,12 @@ class MediaPickerScreenCoordinator: CoordinatorProtocol {
self?.callback(.selectedMediaAtURLs(urls))
}
}
case .documents:
case .documents(let types):
// The document picker automatically dismisses everything on selection
// Strongly retain self in the callback to forward actions correctly
DocumentPicker(selectionType: mode.selectionType, userIndicatorController: userIndicatorController) { action in
DocumentPicker(selectionType: mode.selectionType,
contentTypes: types,
userIndicatorController: userIndicatorController) { action in
switch action {
case .cancel:
self.callback(.cancel)