From afc3bf5cde97aaf4f2cb974cf622b038545fb7fb Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Tue, 15 Oct 2024 14:23:37 +0200 Subject: [PATCH] fix: Dismiss the photo picker view controller to return to the app earlier --- src/Uno.UWP/Storage/Pickers/FileOpenPicker.iOS.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Uno.UWP/Storage/Pickers/FileOpenPicker.iOS.cs b/src/Uno.UWP/Storage/Pickers/FileOpenPicker.iOS.cs index 848d2daa354c..a099da4a6b29 100644 --- a/src/Uno.UWP/Storage/Pickers/FileOpenPicker.iOS.cs +++ b/src/Uno.UWP/Storage/Pickers/FileOpenPicker.iOS.cs @@ -128,7 +128,8 @@ private async Task PickFilesAsync(bool multiple, C var files = await completionSource.Task; - rootController.DismissViewController(true, null); + // Dismiss if still shown + viewController.DismissViewController(true, null); if (files is null || files.Length == 0) { @@ -150,6 +151,7 @@ public override void Canceled(UIImagePickerController picker) => public override void FinishedPickingMedia(UIImagePickerController picker, NSDictionary info) { + if (info.ValueForKey(new NSString("UIImagePickerControllerImageURL")) is NSUrl nSUrl) { var file = StorageFile.GetFromSecurityScopedUrl(nSUrl, null); @@ -171,12 +173,16 @@ public PhotoPickerDelegate(TaskCompletionSource taskCompletionSo public override async void DidFinishPicking(PHPickerViewController picker, PHPickerResult[] results) { + // Dismiss the picker early to get the user back to the app as soon as possible. + picker.DismissViewController(true, null); + var storageFiles = await ConvertPickerResults(results); // This callback can be called multiple times, user tapping multiple times over the "add" button, // we need to ensure that we only set the result once. _taskCompletionSource.TrySetResult(storageFiles.ToArray()); } + private async Task> ConvertPickerResults(PHPickerResult[] results) { List storageFiles = new List(); @@ -198,8 +204,8 @@ private async Task> ConvertPickerResults(PHPickerResult var extension = GetExtension(identifier); var destinationUrl = NSFileManager.DefaultManager - .GetTemporaryDirectory() - .Append($"{NSProcessInfo.ProcessInfo.GloballyUniqueString}.{extension}", false); + .GetTemporaryDirectory() + .Append($"{NSProcessInfo.ProcessInfo.GloballyUniqueString}.{extension}", false); data.Save(destinationUrl, false); storageFiles.Add(StorageFile.GetFromSecurityScopedUrl(destinationUrl, null));