Skip to content

[BUG] Popup V2: ShowPopupAsync never close task in OnAppearing #2816

@Cristian-Azeta

Description

@Cristian-Azeta

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

This is the code snippet that calls ShowPopupAsync

    protected override async void OnAppearing()
    {
        base.OnAppearing();
        IsBusy = true;
        try
        {
            if (String.IsNullOrEmpty(Model.Context.Location))
            {
                IPopupResult<Boolean> result = await PS.ShowPopupAsync<F12LocationPopup, Boolean>(Navigation, new PopupOptions
                {
                    CanBeDismissedByTappingOutsideOfPopup = false,
                    PageOverlayColor = Colors.Orange.WithAlpha(0.4f),
                }, CancellationToken.None);
                if (Model.Step == 0)
                {
                    await this.GoBackAsync(); return;
                }
            }
        }
        catch (Exception ex)
        {
            Vibration.Default.Vibrate(1000);
            await DisplayAlert(Title, ex.Message, GlobalResource.Continue);
        }
        finally
        {
            IsBusy = false;
        }
        WeakReferenceMessenger.Default.Register<ScannerMessage>(this, (r, message) =>
        {
            MainThread.BeginInvokeOnMainThread(() =>
            {
                txtBarcode.Text = ScannerMessage.Parse($"{message.Data}");
                OnBarcodeCompleted(txtBarcode, EventArgs.Empty);
            });
        });
        await Model.Appearing(Sequence);
    }

Expected Behavior

I expect that the task will stop and wait for the response from the popup, and from its response, the task must restart from

if (Model.Step == 0)
{
     await this.GoBackAsync(); return;
}

Steps To Reproduce

In the example ShowPopupInOnAppearingPage, just add a statement afterward ShowPopupAsync and see if it gets executed.

Link to public reproduction project repository

https://github.com/CommunityToolkit/Maui/tree/main/samples

Environment

- .NET MAUI CommunityToolkit:
- OS:
- .NET MAUI:

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions