Skip to content

Commit fd619fb

Browse files
Add public Border PopupBorder { get; } and simplify unit tests
1 parent 14871d6 commit fd619fb

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public void ShowPopupAsync_WithViewType_SetsCorrectDefaults()
192192
navigation.ShowPopup(label);
193193

194194
popupPage = (PopupPage)navigation.ModalStack[0];
195-
autogeneratedPopup = (Popup)(((Border)popupPage.Content.Children.Last()).Content ?? throw new InvalidOperationException("Border Content cannot be null"));
195+
autogeneratedPopup = (Popup)(popupPage.Content.PopupBorder.Content ?? throw new InvalidOperationException("Border Content cannot be null"));
196196

197197
// Assert
198198
Assert.Equal(PopupDefaults.BackgroundColor, autogeneratedPopup.BackgroundColor);
@@ -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.Children.OfType<Border>().Single();
438+
var border = popupPageContent.PopupBorder;
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.Children.OfType<Border>().Single();
510+
var border = popupPageContent.PopupBorder;
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.Children.OfType<Border>().Single();
582+
var border = popupPageContent.PopupBorder;
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.Children.OfType<Border>().Single();
663+
var border = popupPageContent.PopupBorder;
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.Children.OfType<Border>().Single();
169+
var border = popupPageLayout.PopupBorder;
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
@@ -481,7 +481,7 @@ public void PopupPage_ShouldRespectLayoutOptions()
481481

482482
// Act
483483
var popupPage = new PopupPage(view, PopupOptions.Empty);
484-
var border = popupPage.Content.Children.OfType<Border>().Single();
484+
var border = popupPage.Content.PopupBorder;
485485

486486
// Assert
487487
Assert.Equal(LayoutOptions.Start, border.VerticalOptions);

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,29 +188,31 @@ public PopupPageLayout(in Popup popupContent, in IPopupOptions options, in IComm
188188
tappableBackground.GestureRecognizers.Add(new TapGestureRecognizer { Command = tapOutsideOfPopupCommand });
189189
Children.Add(tappableBackground); // Add the Tappable Background to the PopupPageLayout Grid before adding the Border to ensure the Border is displayed on top
190190

191-
var border = new Border
191+
PopupBorder = new Border
192192
{
193193
BackgroundColor = popupContent.BackgroundColor ??= PopupDefaults.BackgroundColor,
194194
Content = popupContent
195195
};
196196

197197
// Bind `Popup` values through to Border using OneWay Bindings
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);
198+
PopupBorder.SetBinding(Border.MarginProperty, static (Popup popup) => popup.Margin, source: popupContent, mode: BindingMode.OneWay);
199+
PopupBorder.SetBinding(Border.PaddingProperty, static (Popup popup) => popup.Padding, source: popupContent, mode: BindingMode.OneWay);
200+
PopupBorder.SetBinding(Border.BackgroundProperty, static (Popup popup) => popup.Background, source: popupContent, mode: BindingMode.OneWay);
201+
PopupBorder.SetBinding(Border.BackgroundColorProperty, static (Popup popup) => popup.BackgroundColor, source: popupContent, mode: BindingMode.OneWay);
202+
PopupBorder.SetBinding(Border.VerticalOptionsProperty, static (Popup popup) => popup.VerticalOptions, source: popupContent, mode: BindingMode.OneWay);
203+
PopupBorder.SetBinding(Border.HorizontalOptionsProperty, static (Popup popup) => popup.HorizontalOptions, source: popupContent, mode: BindingMode.OneWay);
204204

205205
// Bind `PopupOptions` values through to Border using OneWay Bindings
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);
206+
PopupBorder.SetBinding(Border.ShadowProperty, static (IPopupOptions options) => options.Shadow, source: options, mode: BindingMode.OneWay);
207+
PopupBorder.SetBinding(Border.StrokeProperty, static (IPopupOptions options) => options.Shape, source: options, converter: new BorderStrokeConverter(), mode: BindingMode.OneWay);
208+
PopupBorder.SetBinding(Border.StrokeShapeProperty, static (IPopupOptions options) => options.Shape, source: options, mode: BindingMode.OneWay);
209+
PopupBorder.SetBinding(Border.StrokeThicknessProperty, static (IPopupOptions options) => options.Shape, source: options, converter: new BorderStrokeThicknessConverter(), mode: BindingMode.OneWay);
210210

211-
Children.Add(border);
211+
Children.Add(PopupBorder);
212212
}
213213

214+
public Border PopupBorder { get; }
215+
214216
sealed partial class BorderStrokeThicknessConverter : BaseConverterOneWay<Shape?, double>
215217
{
216218
public override double DefaultConvertReturnValue { get; set; } = PopupOptionsDefaults.BorderStrokeThickness;

0 commit comments

Comments
 (0)