Master detail page: PopModalAsync from detail brings back to root

ThibautdThibautd Member ✭✭
edited January 8 in Xamarin.Forms

Hello everyone,

I've been struggling with this super-strange issue.
Here is the flow : from a master-detail page "Catalog" I PushAsync to a page "BookViewPage". Then that "BookViewPage" PushModalAsync an Ad.
The ad close with PopModalAsync, but that brings back the navigation to the Catalog page, not ProductDetails.

Code:
CatalogViewPage.cs

private async void OnItemTapped(Object sender, EventArgs e) 
{
    var selectedItem = ((ListView)sender).SelectedItem;
    var book = (Book)selectedItem;
    var articleView = new BookViewPage(new BookViewModel(book));

    await Navigation.PushAsync(articleView);
}

BookViewPage.cs

    public async void Buy(object sender, EventArgs e)
{
        if (User.CurrentUser == null)
        {
            await Navigation.PushModalAsync(NavigationPageHelper.Create(new SignUpPage(false)));
            return;
        }
    ....
}

SignUpPage.cs

    async void OnCloseButtonClicked(object sender, EventArgs args)
    {
        await Navigation.PopModalAsync();
    }

On close : the navigation goes back to CatalogViewPage.cs

Any help would be greatly appreciated :blush:

Posts

  • ThibautdThibautd Member ✭✭
    edited January 8

    (edited the post: I managed to find the core issue, which I detailed in place)

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @Thibautd Have you started your solution with the built-in Master-Detail template? If you have done that then there shouldn't be any issue.

  • ThibautdThibautd Member ✭✭
    edited January 18

    @ShantimohanElchuri First thank you for your help and your time.
    As you mentioned you were not facing that issue I investigated my code further and found the root of the problem, which is on my side.

    If anyone ever face the same issue, note that in the following navigation stack:
    root page - page 1 - modal 1
    when the modal 1 close, OnAppearing is not only called on page 1 but also on root page, which was the issue for me. I was reassigning the detail page of my master detail in OnAppearing of the root page, thus basically resetting my app every time a pop up (or an overlay such as a native video player, etc.) was closed.

Sign In or Register to comment.