Mopups
Mopups copied to clipboard
BackgroundClickedCommand gets executed twice
Hi, I was testing the BackgroundClickedCommand, and i noticed that it gets executed twice once a popup is closed. below is my xaml code:
<pages:PopupPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:animations="clr-namespace:Mopups.Animations;assembly=Mopups" xmlns:pages="clr-namespace:Mopups.Pages;assembly=Mopups" xmlns:converters="clr-namespace:MarketLeader.Mobile.Application.Converters" xmlns:controls="clr-namespace:MarketLeader.Mobile.Application.Controls" x:Class="MarketLeader.Mobile.Application.Views.ContactTabs.StatusFilterPopup" Title="{Binding Title}" HasSystemPadding="True" CloseWhenBackgroundIsClicked="True" BackgroundClickedCommand="{Binding CloseCommand}" x:Name="statusPopup">
...
could this be a bug?
tested on iOS simulator. im using MVVM, so using the IPopupNavigation with dependency injection
Update: when i set background BackgroundInputTransparent to true, now the command only gets called once. but the popup does not dismiss anymore
I can confirm this issue using Mopups in version 1.1.1
.
I was running my application on a simulator with iOS 16.4. Using all default values for the parameters, the callback OnBackgroundClicked
was called twice when tapping the background.
As a workaround, I defined a custom base-class for all my popups:
public abstract class PopupPageBase : PopupPage
{
public PopupPageBase()
{
BackgroundInputTransparent = true;
CloseWhenBackgroundIsClicked = false;
}
protected override bool OnBackButtonPressed()
{
// handle back button press (Android)
return base.OnBackButtonPressed();
}
protected override bool OnBackgroundClicked()
{
// handle tapping the background (Android + iOS)
return base.OnBackgroundClicked();
}
}
In my app, all navigation is handled within a custom class called "NavigationService". I simply redirect both methods to a method on this object, which than will dismiss the popup.
A drawback of this workaround: the click-event will be passed through to the element below the popup-background. If that element is clickable - e.g. a Button
- it will be activated.