dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

MediaPicker returns the page set by default in the shell #9810

Closed innomarcoItalia closed 2 years ago

innomarcoItalia commented 2 years ago

Description

It needs set default item in shell, when you navigate to the photo page once you run MediaPicker (CapturePhotoAsync () or PickPhotoAsync ()) it returns the start page. If you remove in AppShell.xaml.cs

menuShell.CurrentItem = start;

this works correctly

Steps to Reproduce

Download the attached MauiPhoto project. Compile and run on an Android device

...... comments menuShell.CurrentItem = start in AppShell.xaml.cs

Compile and run on an Android device

MauiPhoto.zip

Version with bug

6.0.486 (current)

Last version that worked well

6.0.400

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

Android 11 - Android 12

Did you find any workaround?

No response

Relevant log output

No response

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

mattleibow commented 2 years ago

The reason this happens is because you are setting the current page to be the start item in OnAppearing. When you navigate to the camera, the page disappears and then reappears - switching back to the start page each time.

If you want to use the OnAppearing, you need to detect if this is the first or subsequent time:

bool firstRun = true;

protected  override void OnAppearing()
{
    base.OnAppearing();

    if (firstRun)
        menuShell.CurrentItem = start;
    firstRun = false;
}

An alternative and maybe nicer way is to set the CurrentItem in the XAML as that is only evaluated once:

<FlyoutItem ... CurrentItem="{Reference start}">