Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Dismiss the photo picker view controller earlier (backport #18475) #18481

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading