Maui icon indicating copy to clipboard operation
Maui copied to clipboard

[Popup] Add `DefaultPopupOptionsSettings` and `DefaultPopupSettings` to `.UseMauiCommunityToolkit(Options)`

Open TheCodeTraveler opened this issue 8 months ago • 1 comments

Description of Change

This PR grants developers the capability to set global default values for every popup in their app using DefaultPopupOptionsSettings and DefaultPopupSettings in.UseMauiCommunityToolkit(Options):

.UseMauiCommunityToolkit(static options =>
{
  options.SetPopupDefaults(new DefaultPopupSettings
  {
	  CanBeDismissedByTappingOutsideOfPopup = true,
	  BackgroundColor = Colors.Orange,
	  HorizontalOptions = LayoutOptions.End,
	  VerticalOptions = LayoutOptions.Start,
	  Margin = 72,
	  Padding = 4
  });
  options.SetPopupOptionsDefaults(new DefaultPopupOptionsSettings
  {
	  CanBeDismissedByTappingOutsideOfPopup = true,
	  OnTappingOutsideOfPopup = () => hasOnTappingOutsideOfPopupExecuted = true,
	  PageOverlayColor = Colors.Orange,
	  Shadow = null,
	  Shape = null
  });
})

PR Checklist

  • [x] Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • [x] Has tests (if omitted, state reason in description)
  • [x] Has samples (if omitted, state reason in description)
  • [x] Rebased on top of main at time of PR
  • [x] Changes adhere to coding standard
  • [ ] Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Additional information

This PR also fixes a bug where View.Padding was improperly being passed through to PopupBorder.Padding

TheCodeTraveler avatar Jun 22 '25 21:06 TheCodeTraveler

I know I initiated this thought process but I wanted to play devils advocate a little before we go further. I do like the idea of allowing developers to define defaults but I want to float some thoughts by you all to see what you think:

  • We should allow developers to control values through a Style which I believe is currently broken (#2747). I am not suggesting we fix it in this PR but I don't want this PR to make it any more difficult to fix
  • ~Perhaps a way to reduce the complexity of multiple possible values for things like CanDismiss... is to accept PopupOptions when passing in a View to the ShowPopup methods and not when passing in a Popup? I know this breaks some symmetry but with Popup but that might not be a bad thing.~ - I originally considered this but have struck it through because I think it causes more issues than it solves.
  • I would like us to make it possible for properties like BackgroundColor and PageOverlayColor to be set using an AppThemeBinding - yes it would be possible via a Style but should it be possible as a default too?

bijington avatar Jun 23 '25 19:06 bijington