mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Prevent multiple file selection callbacks coming from the media upload pickers and generating incorrect transitions in the RoomFlowCoordinator state machine
This commit is contained in:
committed by
Stefan Ceriu
parent
1bbb077e3e
commit
ea91e371eb
@@ -27,9 +27,11 @@ enum DocumentPickerError: Error {
|
||||
}
|
||||
|
||||
struct DocumentPicker: UIViewControllerRepresentable {
|
||||
private weak var userIndicatorController: UserIndicatorControllerProtocol?
|
||||
private let callback: (DocumentPickerAction) -> Void
|
||||
|
||||
init(callback: @escaping (DocumentPickerAction) -> Void) {
|
||||
init(userIndicatorController: UserIndicatorControllerProtocol?, callback: @escaping (DocumentPickerAction) -> Void) {
|
||||
self.userIndicatorController = userIndicatorController
|
||||
self.callback = callback
|
||||
}
|
||||
|
||||
@@ -60,11 +62,21 @@ struct DocumentPicker: UIViewControllerRepresentable {
|
||||
documentPicker.callback(.cancel)
|
||||
}
|
||||
|
||||
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
|
||||
private static let loadingIndicatorIdentifier = "DocumentPickerLoadingIndicator"
|
||||
|
||||
func documentPicker(_ picker: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
|
||||
guard let url = urls.first else {
|
||||
documentPicker.callback(.error(DocumentPickerError.unknown))
|
||||
return
|
||||
}
|
||||
|
||||
picker.delegate = nil
|
||||
|
||||
documentPicker.userIndicatorController?.submitIndicator(UserIndicator(id: Self.loadingIndicatorIdentifier, type: .modal, title: L10n.commonLoading))
|
||||
defer {
|
||||
documentPicker.userIndicatorController?.retractIndicatorWithId(Self.loadingIndicatorIdentifier)
|
||||
}
|
||||
|
||||
do {
|
||||
let newURL = try FileManager.default.copyFileToTemporaryDirectory(file: url)
|
||||
documentPicker.callback(.selectFile(newURL))
|
||||
|
||||
Reference in New Issue
Block a user