Skip to content

Commit 14871d6

Browse files
Add in, Rename to tappableBackground , Move Border Initialization after tappableBackground code
1 parent d429c50 commit 14871d6

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public PopupPage(Popup popup, IPopupOptions popupOptions)
4747
popupOptions.OnTappingOutsideOfPopup?.Invoke();
4848
await CloseAsync(new PopupResult(true));
4949
}, () => popupOptions.CanBeDismissedByTappingOutsideOfPopup);
50-
50+
5151
// Only set the content if the parent constructor hasn't set the content already; don't override content if it already exists
5252
base.Content = new PopupPageLayout(popup, popupOptions, tapOutsideOfPopupCommand);
5353

@@ -103,15 +103,15 @@ public async Task CloseAsync(PopupResult result, CancellationToken token = defau
103103

104104
popupClosedEventManager.HandleEvent(this, result, nameof(PopupClosed));
105105
}
106-
106+
107107
protected override bool OnBackButtonPressed()
108108
{
109109
// Only close the Popup if PopupOptions.CanBeDismissedByTappingOutsideOfPopup is true
110110
if (popupOptions.CanBeDismissedByTappingOutsideOfPopup)
111111
{
112112
CloseAsync(new PopupResult(true), CancellationToken.None).SafeFireAndForget();
113113
}
114-
114+
115115
// Always return true to let the Android Operating System know that we are manually handling the Navigation request from the Android Back Button
116116
return true;
117117
}
@@ -175,24 +175,24 @@ void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query)
175175

176176
internal sealed partial class PopupPageLayout : Grid
177177
{
178-
public PopupPageLayout(in Popup popupContent, in IPopupOptions options, ICommand tapOutsideOfPopupCommand)
178+
public PopupPageLayout(in Popup popupContent, in IPopupOptions options, in ICommand tapOutsideOfPopupCommand)
179179
{
180180
Background = BackgroundColor = null;
181181

182+
var tappableBackground = new BoxView
183+
{
184+
BackgroundColor = Colors.Transparent,
185+
HorizontalOptions = LayoutOptions.Fill,
186+
VerticalOptions = LayoutOptions.Fill
187+
};
188+
tappableBackground.GestureRecognizers.Add(new TapGestureRecognizer { Command = tapOutsideOfPopupCommand });
189+
Children.Add(tappableBackground); // Add the Tappable Background to the PopupPageLayout Grid before adding the Border to ensure the Border is displayed on top
190+
182191
var border = new Border
183192
{
184193
BackgroundColor = popupContent.BackgroundColor ??= PopupDefaults.BackgroundColor,
185194
Content = popupContent
186195
};
187-
188-
var backgroundGrid = new BoxView
189-
{
190-
BackgroundColor = Colors.Transparent,
191-
};
192-
193-
backgroundGrid.GestureRecognizers.Add(new TapGestureRecognizer { Command = tapOutsideOfPopupCommand });
194-
195-
Children.Add(backgroundGrid);
196196

197197
// Bind `Popup` values through to Border using OneWay Bindings
198198
border.SetBinding(Border.MarginProperty, static (Popup popup) => popup.Margin, source: popupContent, mode: BindingMode.OneWay);

0 commit comments

Comments
 (0)