CommunityToolkit / CommunityToolkit/Maui
[BUG] Somtime, Popup2 ShowPopupAsync() calls do not return when other WindowOverlay exists.
- Dominant language
- C#
- Stars
- 2.7k
- Forks
- 500
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 7
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Did you read the "Reporting a bug" section on Contributing file?
- [x] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
### Current Behavior
There exists another library that uses WindowOverlay.
If ShowPopupAsync() is called while another WindowOverlay is displayed, it may rarely return from the ShowPopupAsync() call when the popup is closed.
If another WindowOverlay does not exist, this phenomenon will not occur.
### Expected Behavior
Return from ShowPopupAsync() call when Popup is closed, even if another Overlay exists.
### Steps To Reproduce
1. Create another WindowOverlay.
2. Show WindowOverlay.
3. Call to ShowPopupAsync().
4. Close Popup.
5. Repeat about 10 times and you can almost reproduce it.
The sample code is below.
When a popup is repeatedly displayed and closed by OnWithOverlayClick(), the “** end” may not be displayed after the popup disappears, and the BusyOverlay may remain.
```xml
```
```csharp
using System.Diagnostics;
using CommunityToolkit.Maui;
namespace Popup2App
{
using CommunityToolkit.Maui.Extensions;
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
// Overlay issue
private async void OnWithOverlayClick(object? sender, EventArgs e)
{
var overlay = new BusyOverlay(Application.Current!.Windows[0]);
overlay.Window.AddOverlay(overlay);
Debug.WriteLine("** start");
await this.ShowPopupAsync(new SamplePopup(), new PopupOptions { Shape = null, Shadow = null });
Debug.WriteLine("** end");
overlay.Window.RemoveOverlay(overlay);
}
private async void OnWithoutOverlayClick(object? sender, EventArgs e)
{
Debug.WriteLine("** start");
await this.ShowPopupAsync(new SamplePopup(), new PopupOptions { Shape = null, Shadow = null });
Debug.WriteLine("** end");
}
}
}
public sealed class BusyOverlay : WindowOverlay
{
public BusyOverlay(IWindow window)
: base(window)
{
AddWindowElement(new OverlayElement());
EnableDrawableTouchHandling = true;
}
private sealed class OverlayElement : IWindowOverlayElement
{
public void Draw(ICanvas canvas, RectF dirtyRect)
{
canvas.FillColor = new(255, 0, 0, 128);
canvas.FillRectangle(dirtyRect);
}
public bool Contains(Point point) => true;
}
}
```
### Link to public reproduction project repository
https://github.com/usausa/Issue-CommunityToolkitMaui-Popup2
### Environment
```markdown
- .NET MAUI CommunityToolkit: 12.0.0
- OS: Android
- .NET MAUI: 9.0.80
```
### Anything else?
_No response_
Contributor guide
Research direction
Start with the OnWithOverlayClick() reproduction in the linked project, especially the ShowPopupAsync() call and the BusyOverlay add/remove sequence. Run the Android sample repeatedly with another WindowOverlay present and trace the popup-close completion path. Done means ShowPopupAsync() returns reliably after the popup closes and the BusyOverlay is removed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, csharp
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100