Skip to content

Commit

Permalink
Merge pull request #18475 from unoplatform/dev/mazi/phpicker-dismiss
Browse files Browse the repository at this point in the history
fix: Dismiss the photo picker view controller earlier
  • Loading branch information
jeromelaban authored Oct 16, 2024
2 parents 788264e + afc3bf5 commit 95925d7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Uno.UWP/Storage/Pickers/FileOpenPicker.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ private async Task<FilePickerSelectedFilesArray> 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)
{
Expand All @@ -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);
Expand All @@ -171,12 +173,16 @@ public PhotoPickerDelegate(TaskCompletionSource<StorageFile?[]> 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<IEnumerable<StorageFile>> ConvertPickerResults(PHPickerResult[] results)
{
List<StorageFile> storageFiles = new List<StorageFile>();
Expand All @@ -198,8 +204,8 @@ private async Task<IEnumerable<StorageFile>> 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));
Expand Down

0 comments on commit 95925d7

Please sign in to comment.