question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PushPopupAsync() returns before popup is actually displayed

See original GitHub issue

await Navigation.PushPopupAsync(popup, false);

You can await this but… The call returns before the popup is actually displayed. So more like when the popup system receives the request for the popup to be displayed.

I’ve had a few situations were I await the push, do some work, dismiss the popup BEFORE IT ACTUALLY APPEARS… then the popup appears… and is on screen forever now because my code already dismissed it.

I shouldn’t be running into race conditions on something I await.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:57 (22 by maintainers)

github_iconTop GitHub Comments

2reactions
solomonfriedcommented, Sep 18, 2018

@tlhintoq my code can await until popup is closed, or not await, depends on the logic 😃

public async Task ShowMyPopupAsync(object context, bool waitUntilClosed = false)
{
     var myPopup = new MyPopup { BindingContext = context };
     if (waitUntilClosed)
          await myPopup.PopupClosedTask;
}

and your Page (which you showing as popup) will contain next:

public partial class MyPopup : Rg.Plugins.Popup.Pages.PopupPage
{
     private TaskCompletionSource<bool> taskCompletionSource;
     public Task PopupClosedTask { get { return taskCompletionSource.Task; } }

     public MyPopup()
     {
          InitializeComponent();
     }

     protected override void OnAppearing()
     {
          base.OnAppearing();
          taskCompletionSource = new TaskCompletionSource<bool>();
     }

     protected override void OnDisappearing()
     {
          base.OnDisappearing();
          taskCompletionSource.SetResult(true);
     }
}

You can also make PopupClosedTask as interface and implement for any Page

This is just what I was looking for. With the new tuple support in c#, I can easily return multiple objects without having to create a new class. In my popup, I am accepting a string for a prompt which is stored in a UserText property. I also have an Accept and Cancel button. The Accept button assigns ‘true’ to an Accepted property. Then your OnDisappearing method becomes.

private TaskCompletionSource<(bool isAccepted , string userText)> _taskCompletionSource;
public Task<(bool isAccepted, string userText)> PopupClosedTask => _taskCompletionSource.Task;

protected override void OnDisappearing()
{
     base.OnDisappearing();
     taskCompletionSource.SetResult((Accepted, UserText));
}

My calling code looks like…

await PopupNavigation.Instance.PushAsync(inputPopup,true);
var ret = await inputPopup.PopupClosedTask;

Debug.WriteLine($"{ret.isAccepted} - {ret.userText}");

Thanks.

1reaction
alezhukcommented, May 15, 2017

@tlhintoq my code can await until popup is closed, or not await, depends on the logic 😃

public async Task ShowMyPopupAsync(object context, bool waitUntilClosed = false)
{
     var myPopup = new MyPopup { BindingContext = context };
     if (waitUntilClosed)
          await myPopup.PopupClosedTask;
}

and your Page (which you showing as popup) will contain next:

public partial class MyPopup : Rg.Plugins.Popup.Pages.PopupPage
{
     private TaskCompletionSource<bool> taskCompletionSource;
     public Task PopupClosedTask { get { return taskCompletionSource.Task; } }

     public MyPopup()
     {
          InitializeComponent();
     }

     protected override void OnAppearing()
     {
          base.OnAppearing();
          taskCompletionSource = new TaskCompletionSource<bool>();
     }

     protected override void OnDisappearing()
     {
          base.OnDisappearing();
          taskCompletionSource.SetResult(true);
     }
}

You can also make PopupClosedTask as interface and implement for any Page

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pause a method till getting response from Rg. ...
I am using Rg.Plugins.Popup for a simple confirmation popup before deleting an item from the list like "Are you sure you want to...
Read more >
So I created a Popup with Transparent background in Xamarin ...
PushModalAsync() as what we normally do in Xamarin Forms, yes of course you could do the same to open this Transparent Popup page,...
Read more >
Xamarin Community Toolkit Popup
The Popup control allows developers to create and display popups within their applications. The Popup can be extended to return data to the ......
Read more >
Ajeromi central school
But, by clicking back button in phone, again the same popup is shown. But there is a really nice library which allow to...
Read more >
Pixel-Perfect, Customizable Popups for Xamarin.Forms with ...
... Add New PopupPage 12:03 - PopupPage Navigation/ Show Popup 14:30 - Our First Popup On Screen 15:06 - Customize Popup Look and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found