-
Notifications
You must be signed in to change notification settings - Fork 464
Prevent a tap inside the content from closing a popup #2741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the popup page layout to only close when tapping outside the popup content, rather than anywhere on the page.
- Removed the old gesture recognizer on the entire content and now injects a tap command into a dedicated background grid.
- Updated
PopupPageLayoutconstructor to accept the outside-tap command and add a transparent grid covering the full page behind the popup. - Kept existing behaviors by only setting content when not already provided by the base constructor.
Comments suppressed due to low confidence (1)
src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs:188
- Add unit or UI tests to confirm that taps inside the popup content do not close the popup, and that taps outside do trigger the close behavior.
var backgroundGrid = new Grid();
|
Yeah I wasn't keen on this approach but hadn't considered your suggestion. I'll try that out |
|
Update: I confirmed that we can fix #2730 by just adding an empty internal sealed partial class PopupPageLayout : Grid
{
public PopupPageLayout(in Popup popupContent, in IPopupOptions options)
{
Background = BackgroundColor = null;
var border = new Border
{
BackgroundColor = popupContent.BackgroundColor ??= PopupDefaults.BackgroundColor,
Content = popupContent
};
border.GestureRecognizers.Add(new TapGestureRecognizer()); // < --- This resolves the problem without modifying any other code in `PopupPage`.
// Bind `Popup` values through to Border using OneWay Bindings
border.SetBinding(Border.MarginProperty, static (Popup popup) => popup.Margin, source: popupContent, mode: BindingMode.OneWay);
border.SetBinding(Border.PaddingProperty, static (Popup popup) => popup.Padding, source: popupContent, mode: BindingMode.OneWay);
border.SetBinding(Border.BackgroundProperty, static (Popup popup) => popup.Background, source: popupContent, mode: BindingMode.OneWay);
border.SetBinding(Border.BackgroundColorProperty, static (Popup popup) => popup.BackgroundColor, source: popupContent, mode: BindingMode.OneWay);
border.SetBinding(Border.VerticalOptionsProperty, static (Popup popup) => popup.VerticalOptions, source: popupContent, mode: BindingMode.OneWay);
border.SetBinding(Border.HorizontalOptionsProperty, static (Popup popup) => popup.HorizontalOptions, source: popupContent, mode: BindingMode.OneWay);
// Bind `PopupOptions` values through to Border using OneWay Bindings
border.SetBinding(Border.ShadowProperty, static (IPopupOptions options) => options.Shadow, source: options, mode: BindingMode.OneWay);
border.SetBinding(Border.StrokeProperty, static (IPopupOptions options) => options.Shape, source: options, converter: new BorderStrokeConverter(), mode: BindingMode.OneWay);
border.SetBinding(Border.StrokeShapeProperty, static (IPopupOptions options) => options.Shape, source: options, mode: BindingMode.OneWay);
border.SetBinding(Border.StrokeThicknessProperty, static (IPopupOptions options) => options.Shape, source: options, converter: new BorderStrokeThicknessConverter(), mode: BindingMode.OneWay);
Children.Add(border);
}
sealed partial class BorderStrokeThicknessConverter : BaseConverterOneWay<Shape?, double>
{
public override double DefaultConvertReturnValue { get; set; } = PopupOptionsDefaults.BorderStrokeThickness;
public override double ConvertFrom(Shape? value, CultureInfo? culture) => value?.StrokeThickness ?? 0;
}
sealed partial class BorderStrokeConverter : BaseConverterOneWay<Shape?, Brush?>
{
public override Brush? DefaultConvertReturnValue { get; set; } = PopupOptionsDefaults.BorderStroke;
public override Brush? ConvertFrom(Shape? value, CultureInfo? culture) => value?.Stroke;
}
} |
|
Thanks I can apply that change now. Out of interest do you know why we have this line:
|
This reverts commit 173356b.
|
Although given we have a strange selection bug reported with CollectionView I am keen to see if this proposal plays well with that scenario. UPDATE: The proposal of the empty |
…oolkit/Maui into feature/sl-fix-tapping-inside
Refactored PopupPageLayout to expose the Border via a property instead of accessing it through the Children collection. Updated PopupPage to add gesture recognizers directly and simplified content initialization. Adjusted related unit tests to use the new Border property for improved clarity and maintainability.
…ed inside" This reverts commit d17876e.
Ah - yea, we can update that to replace |
TheCodeTraveler
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Shaun! Approved ✅
FYI - I add public Border PopupBorder { get; } to PopupPageLayout to help us simplify the Unit Tests a bit.


Description of Change
Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information