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

iOS MediaPicker.CapturePhotoAsync closes the wrong modal #27513

Open
jasells opened this issue Feb 1, 2025 · 0 comments
Open

iOS MediaPicker.CapturePhotoAsync closes the wrong modal #27513

jasells opened this issue Feb 1, 2025 · 0 comments
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/iOS 🍎 t/bug Something isn't working

Comments

@jasells
Copy link

jasells commented Feb 1, 2025

Description

After MediaPicker.CapturePhotoAsync() returns the FileResult, the Camera modal is still on screen. If subsequent code tries to open a modal like:

        var photo = await MediaPicker.CapturePhotoAsync();
        Debug.WriteLine($"===== FileResult from cam: {photo?.FullPath.ToString() ?? "null"}");

        if (photo == null) { return new CropResult(); }
        
        SKBitmap bmp;
        using (var imStr = await photo.OpenReadAsync())
        {
            bmp = SKBitmap.Decode(imStr);
        }

        var tcs = new TaskCompletionSource<CropResult>();

        var saved = (CropResult x) =>
            {
                onCropComplete?.Invoke(x);
                tcs.TrySetResult(x);
            };

        // this modal/page won't show as written, though it works on Android, Windows.
        var navt = Application.Current?.MainPage?
                                       .Navigation
                                       .PushModalAsync(new ImageCropperPage(imageCropperConfig,
                                                                            saved));

the new modal won't display or is closed with the Camera modal?

I think the task from .CapturePhotoAsync() is returning before the Camera modal close() + close animations are complete, and so it is also closing the new modal just added to stack?

Steps to Reproduce

Build/run the app for iOS (I am currently using Rider). In app, click the "test" link btn on bottom right, then click "From Camera" btn.

Link to public reproduction project repository

https://xdevapps.visualstudio.com/DefaultCollection/XDev.Maui.ManualCrop/_git/XDev.Maui.ManualCrop

Version with bug

8.0.100 SR10

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

No response

Affected platforms

iOS

Affected platform versions

iOS 17.5, 17.2

Did you find any workaround?

yes.

this code is the work around, by dispatching the call to Application.Current?.MainPage?.Navigation.PushModalAsync() I think it allows the new modal navigation run after MediaPicker.CapturePhotoAsync() completes the camera display UI close animation, and everything works as expected.

return await _dispatcher.DispatchAsync(() => ShowAsync((SKBitmapImageSource)bmp,
                                                               imageCropperConfig,
                                                               onCropComplete));

Relevant log output

@jasells jasells added the t/bug Something isn't working label Feb 1, 2025
@jsuarezruiz jsuarezruiz added platform/iOS 🍎 area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info labels Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/iOS 🍎 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants