-
Notifications
You must be signed in to change notification settings - Fork 464
[Popup] Add DefaultPopupOptionsSettings and DefaultPopupSettings to .UseMauiCommunityToolkit(Options)
#2759
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
[Popup] Add DefaultPopupOptionsSettings and DefaultPopupSettings to .UseMauiCommunityToolkit(Options)
#2759
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 introduces global default settings for popups and popup options, allowing developers to configure defaults via UseMauiCommunityToolkit(Options), and refactors existing default classes. It also fixes how popup padding is applied and updates related bindings and tests.
- Introduce
DefaultPopupSettingsandDefaultPopupOptionsSettingsrecords and remove old static defaults. - Update
PopupPage,Popup, converters, andOptionsto use the new default records and accept nullable options. - Refresh unit tests and sample to align with the new default-setting APIs.
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs | Accept nullable options, bind new defaults, update converters |
| src/CommunityToolkit.Maui/Views/Popup/PopupOptions.shared.cs | Change bindable property defaults to use Options.DefaultPopupOptionsSettings |
| src/CommunityToolkit.Maui/Views/Popup/Popup.shared.cs | Initialize Popup defaults from Options.DefaultPopupSettings |
| src/CommunityToolkit.Maui/Primitives/Defaults/PopupOptionsDefaults.shared.cs | Remove obsolete static defaults class |
| src/CommunityToolkit.Maui/Primitives/Defaults/PopupDefaults.shared.cs | Remove obsolete static defaults class |
| src/CommunityToolkit.Maui/Primitives/DefaultPopupSettings.cs | Add DefaultPopupSettings record |
| src/CommunityToolkit.Maui/Primitives/DefaultPopupOptionsSettings.cs | Add DefaultPopupOptionsSettings record |
| src/CommunityToolkit.Maui/Options.cs | Add storage and setters for default popup settings and options |
| src/CommunityToolkit.Maui/Extensions/PopupExtensions.shared.cs | Drop fallback to PopupOptions.Empty, rely on nullable handling |
| samples/CommunityToolkit.Maui.Sample/MauiProgram.cs | Invoke new SetPopupDefaults and SetPopupOptionsDefaults |
Comments suppressed due to low confidence (5)
src/CommunityToolkit.Maui/Options.cs:17
- The #error directive will block compilation for .NET 10 and later; remove the conditional branch and public constructor to prevent build failures and streamline the Options API.
#error Remove .NET 9 code now that we're upgrading to .NET 10; Options should not have a public constructor, only public methods. Having a public constructor allows developers to override the values set when using AppBuilderExtensions
src/CommunityToolkit.Maui/Primitives/DefaultPopupSettings.cs:32
- [nitpick] The nested class
PopupDefaultsinsideDefaultPopupSettingsconflicts in naming with the removed globalPopupDefaults; consider renaming it to clarify its scope (e.g.,DefaultValues).
static class PopupDefaults
src/CommunityToolkit.Maui/Primitives/DefaultPopupOptionsSettings.cs:29
- [nitpick] The nested class
PopupOptionsDefaultsinsideDefaultPopupOptionsSettingsshares a name with the old global defaults; renaming it (e.g., toDefaultValues) would reduce confusion.
static class PopupOptionsDefaults
src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs:138
- This binding no longer uses the VerticalOptionsConverter, so default fallback values won't be applied when view.VerticalOptions is Fill; add the converter to apply
Options.DefaultPopupSettings.VerticalOptions.
popup.SetBinding(Popup.VerticalOptionsProperty, static (View view) => view.VerticalOptions, source: view, mode: BindingMode.OneWay);
src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs:139
- This binding no longer uses the HorizontalOptionsConverter, so default fallback values won't be applied when view.HorizontalOptions is Fill; add the converter to apply
Options.DefaultPopupSettings.HorizontalOptions.
popup.SetBinding(Popup.HorizontalOptionsProperty, static (View view) => view.HorizontalOptions, source: view, mode: BindingMode.OneWay);
|
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:
|
bijington
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.
Hey @TheCodeTraveler good work on this! I have added 2 comments - one to help me understand what needs to be documented and another mostly just explaining why I took so long to review. Feel free to resolve the comments and merge.
Description of Change
This PR grants developers the capability to set global default values for every popup in their app using
DefaultPopupOptionsSettingsandDefaultPopupSettingsin.UseMauiCommunityToolkit(Options):PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRDefaultPopupSettingsandDefaultPopupOptionsSettingsMicrosoftDocs/CommunityToolkit#574Additional information
This PR also fixes a bug where
View.Paddingwas improperly being passed through toPopupBorder.Padding