Skip to content

Commit b99d980

Browse files
Revert "Add GestureRecognizer to Prevent Popup from closing when tapped inside"
This reverts commit d17876e.
1 parent 3896462 commit b99d980

File tree

4 files changed

+34
-29
lines changed

4 files changed

+34
-29
lines changed

src/CommunityToolkit.Maui.UnitTests/Extensions/PopupExtensionsTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public void ShowPopupAsync_WithCustomOptions_AppliesOptions()
435435

436436
var popupPage = (PopupPage)navigation.ModalStack[0];
437437
var popupPageContent = popupPage.Content;
438-
var border = popupPageContent.Border;
438+
var border = (Border)popupPageContent.Children[0];
439439
var popup = border.Content;
440440

441441
// Assert
@@ -507,7 +507,7 @@ public void ShowPopupAsync_Shell_WithCustomOptions_AppliesOptions()
507507

508508
var popupPage = (PopupPage)shellNavigation.ModalStack[0];
509509
var popupPageContent = popupPage.Content;
510-
var border = popupPageContent.Border;
510+
var border = (Border)popupPageContent.Children[0];
511511
var popup = border.Content;
512512

513513
// Assert
@@ -579,7 +579,7 @@ public void ShowPopupAsyncWithView_WithCustomOptions_AppliesOptions()
579579

580580
var popupPage = (PopupPage)navigation.ModalStack[0];
581581
var popupPageContent = popupPage.Content;
582-
var border = popupPageContent.Border;
582+
var border = (Border)popupPageContent.Children[0];
583583
var popup = (Popup)(border.Content ?? throw new InvalidCastException());
584584

585585
// Assert
@@ -660,7 +660,7 @@ public void ShowPopupAsyncWithView_Shell_WithCustomOptions_AppliesOptions()
660660

661661
var popupPage = (PopupPage)shellNavigation.ModalStack[0];
662662
var popupPageContent = popupPage.Content;
663-
var border = popupPageContent.Border;
663+
var border = (Border)popupPageContent.Children[0];
664664
var popup = (Popup)(border.Content ?? throw new InvalidCastException());
665665

666666
// Assert

src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public void ShowPopupAsync_WithCustomOptions_AppliesOptions()
166166

167167
var popupPage = (PopupPage)navigation.ModalStack[0];
168168
var popupPageLayout = popupPage.Content;
169-
var border = popupPageLayout.Border;
169+
var border = (Border)popupPageLayout.Children[0];
170170
var popup = border.Content;
171171

172172
// Assert

src/CommunityToolkit.Maui.UnitTests/Views/Popup/PopupPageTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ public void PopupPage_ShouldRespectLayoutOptions()
472472

473473
// Act
474474
var popupPage = new PopupPage(view, PopupOptions.Empty);
475-
var border = popupPage.Content.Border;
475+
var border = (Border)popupPage.Content.Children[0];
476476

477477
// Assert
478478
Assert.Equal(LayoutOptions.Start, border.VerticalOptions);

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

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.ComponentModel;
22
using System.Globalization;
3+
using System.Windows.Input;
34
using CommunityToolkit.Maui.Converters;
45
using CommunityToolkit.Maui.Core;
56
using CommunityToolkit.Maui.Extensions;
@@ -41,16 +42,14 @@ public PopupPage(Popup popup, IPopupOptions popupOptions)
4142
this.popup = popup;
4243
this.popupOptions = popupOptions;
4344

44-
// Only set the content if the parent constructor hasn't set the content already; don't override content if it already exists
45-
base.Content ??= new PopupPageLayout(popup, popupOptions);
46-
4745
tapOutsideOfPopupCommand = new Command(async () =>
4846
{
4947
popupOptions.OnTappingOutsideOfPopup?.Invoke();
5048
await CloseAsync(new PopupResult(true));
5149
}, () => popupOptions.CanBeDismissedByTappingOutsideOfPopup);
52-
53-
Content.GestureRecognizers.Add(new TapGestureRecognizer { Command = tapOutsideOfPopupCommand });
50+
51+
// Only set the content if the parent constructor hasn't set the content already; don't override content if it already exists
52+
base.Content ??= new PopupPageLayout(popup, popupOptions, tapOutsideOfPopupCommand);
5453

5554
if (popupOptions is BindableObject bindablePopupOptions)
5655
{
@@ -104,15 +103,15 @@ public async Task CloseAsync(PopupResult result, CancellationToken token = defau
104103

105104
popupClosedEventManager.HandleEvent(this, result, nameof(PopupClosed));
106105
}
107-
106+
108107
protected override bool OnBackButtonPressed()
109108
{
110109
// Only close the Popup if PopupOptions.CanBeDismissedByTappingOutsideOfPopup is true
111110
if (popupOptions.CanBeDismissedByTappingOutsideOfPopup)
112111
{
113112
CloseAsync(new PopupResult(true), CancellationToken.None).SafeFireAndForget();
114113
}
115-
114+
116115
// Always return true to let the Android Operating System know that we are manually handling the Navigation request from the Android Back Button
117116
return true;
118117
}
@@ -176,36 +175,42 @@ void IQueryAttributable.ApplyQueryAttributes(IDictionary<string, object> query)
176175

177176
internal sealed partial class PopupPageLayout : Grid
178177
{
179-
public PopupPageLayout(in Popup popupContent, in IPopupOptions options)
178+
public PopupPageLayout(in Popup popupContent, in IPopupOptions options, ICommand tapOutsideOfPopupCommand)
180179
{
181180
Background = BackgroundColor = null;
182181

183-
Border = new Border
182+
var border = new Border
184183
{
185184
BackgroundColor = popupContent.BackgroundColor ??= PopupDefaults.BackgroundColor,
186185
Content = popupContent
187186
};
188-
Border.GestureRecognizers.Add(new TapGestureRecognizer()); // Blocks `tapOutsideOfPopupCommand` from closing the Popup when the content is tapped
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);
189196

190197
// Bind `Popup` values through to Border using OneWay Bindings
191-
Border.SetBinding(Border.MarginProperty, static (Popup popup) => popup.Margin, source: popupContent, mode: BindingMode.OneWay);
192-
Border.SetBinding(Border.PaddingProperty, static (Popup popup) => popup.Padding, source: popupContent, mode: BindingMode.OneWay);
193-
Border.SetBinding(Border.BackgroundProperty, static (Popup popup) => popup.Background, source: popupContent, mode: BindingMode.OneWay);
194-
Border.SetBinding(Border.BackgroundColorProperty, static (Popup popup) => popup.BackgroundColor, source: popupContent, mode: BindingMode.OneWay);
195-
Border.SetBinding(Border.VerticalOptionsProperty, static (Popup popup) => popup.VerticalOptions, source: popupContent, mode: BindingMode.OneWay);
196-
Border.SetBinding(Border.HorizontalOptionsProperty, static (Popup popup) => popup.HorizontalOptions, source: popupContent, mode: BindingMode.OneWay);
198+
border.SetBinding(Border.MarginProperty, static (Popup popup) => popup.Margin, source: popupContent, mode: BindingMode.OneWay);
199+
border.SetBinding(Border.PaddingProperty, static (Popup popup) => popup.Padding, source: popupContent, mode: BindingMode.OneWay);
200+
border.SetBinding(Border.BackgroundProperty, static (Popup popup) => popup.Background, source: popupContent, mode: BindingMode.OneWay);
201+
border.SetBinding(Border.BackgroundColorProperty, static (Popup popup) => popup.BackgroundColor, source: popupContent, mode: BindingMode.OneWay);
202+
border.SetBinding(Border.VerticalOptionsProperty, static (Popup popup) => popup.VerticalOptions, source: popupContent, mode: BindingMode.OneWay);
203+
border.SetBinding(Border.HorizontalOptionsProperty, static (Popup popup) => popup.HorizontalOptions, source: popupContent, mode: BindingMode.OneWay);
197204

198205
// Bind `PopupOptions` values through to Border using OneWay Bindings
199-
Border.SetBinding(Border.ShadowProperty, static (IPopupOptions options) => options.Shadow, source: options, mode: BindingMode.OneWay);
200-
Border.SetBinding(Border.StrokeProperty, static (IPopupOptions options) => options.Shape, source: options, converter: new BorderStrokeConverter(), mode: BindingMode.OneWay);
201-
Border.SetBinding(Border.StrokeShapeProperty, static (IPopupOptions options) => options.Shape, source: options, mode: BindingMode.OneWay);
202-
Border.SetBinding(Border.StrokeThicknessProperty, static (IPopupOptions options) => options.Shape, source: options, converter: new BorderStrokeThicknessConverter(), mode: BindingMode.OneWay);
206+
border.SetBinding(Border.ShadowProperty, static (IPopupOptions options) => options.Shadow, source: options, mode: BindingMode.OneWay);
207+
border.SetBinding(Border.StrokeProperty, static (IPopupOptions options) => options.Shape, source: options, converter: new BorderStrokeConverter(), mode: BindingMode.OneWay);
208+
border.SetBinding(Border.StrokeShapeProperty, static (IPopupOptions options) => options.Shape, source: options, mode: BindingMode.OneWay);
209+
border.SetBinding(Border.StrokeThicknessProperty, static (IPopupOptions options) => options.Shape, source: options, converter: new BorderStrokeThicknessConverter(), mode: BindingMode.OneWay);
203210

204-
Children.Add(Border);
211+
Children.Add(border);
205212
}
206213

207-
public Border Border { get; }
208-
209214
sealed partial class BorderStrokeThicknessConverter : BaseConverterOneWay<Shape?, double>
210215
{
211216
public override double DefaultConvertReturnValue { get; set; } = PopupOptionsDefaults.BorderStrokeThickness;

0 commit comments

Comments
 (0)