Skip to content

Conversation

@ne0rrmatrix
Copy link
Member

@ne0rrmatrix ne0rrmatrix commented Dec 6, 2025

Description of Change

This pull request refactors how bindable properties are defined and used in the Popup and PopupOptions classes. Instead of manually declaring backing BindableProperty fields and property wrappers, it leverages the [BindableProperty] attribute to auto-generate these properties, resulting in cleaner and more maintainable code. Additionally, the XML documentation for properties has been improved for clarity.

Refactoring of bindable properties:

  • Replaced manual BindableProperty declarations and property wrappers in Popup (Popup.shared.cs) with auto-generated properties using the [BindableProperty] attribute for Margin, Padding, HorizontalOptions, VerticalOptions, and CanBeDismissedByTappingOutsideOfPopup.
  • Similarly, updated PopupOptions (PopupOptions.shared.cs) to use [BindableProperty] for CanBeDismissedByTappingOutsideOfPopup, OnTappingOutsideOfPopup, PageOverlayColor, Shape, and Shadow, removing manual property logic.

Documentation improvements:

  • Enhanced XML documentation comments for bindable properties in both Popup and PopupOptions to be more descriptive and consistent. [1] [2]

Code cleanup:

  • Removed redundant property wrappers and backing fields that are no longer necessary due to the use of auto-generated bindable properties. [1] [2]

General:

  • Added missing using System.ComponentModel; directive to support the [BindableProperty] attribute.

PR Checklist

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

Additional information

Not sure if using a static object is best approach but it works. I am hoping for input on whether to use that or if anyone has any better ideas?

Replaced manual BindableProperty implementations with the
BindableProperty attribute in the `Popup` and `PopupOptions`
classes. This simplifies property definitions, reduces boilerplate,
and improves code readability.

Updated properties such as `Margin`, `Padding`, `HorizontalOptions`,
and `VerticalOptions` in `Popup`, and `CanBeDismissedByTappingOutsideOfPopup`,
`OnTappingOutsideOfPopup`, `PageOverlayColor`, `Shape`, and `Shadow`
in `PopupOptions` to use the attribute with default value creators.

Removed redundant manual property implementations as they are now
handled by the BindableProperty attribute.
Copilot AI review requested due to automatic review settings December 6, 2025 15:19
Copy link
Contributor

Copilot AI left a 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 pull request refactors the Popup and PopupOptions classes to use the [BindableProperty] attribute for auto-generating bindable properties instead of manually declaring them. While the intent to modernize the code is good, there are several critical bugs that prevent this code from working correctly.

Key Changes:

  • Replaced manual BindableProperty declarations with [BindableProperty] attributes in both Popup and PopupOptions classes
  • Improved XML documentation for better clarity
  • Removed redundant property wrappers and backing fields

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/CommunityToolkit.Maui/Views/Popup/Popup.shared.cs Added using System.ComponentModel;, converted 5 properties to use [BindableProperty] attribute with default value creators, and removed manual property implementations
src/CommunityToolkit.Maui/Views/Popup/PopupOptions.shared.cs Converted 5 properties to use [BindableProperty] attribute with default value creators and removed manual property implementations

Copilot AI review requested due to automatic review settings December 6, 2025 16:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

Comment on lines +23 to +24
public partial Action? OnTappingOutsideOfPopup { get; set; }
static object? CreateOnTappingOutsideOfPopup(BindableObject? _) => Options.DefaultPopupOptionsSettings.OnTappingOutsideOfPopup;
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nullability mismatch: The property is declared as non-nullable Action, but the default value creator method returns object? (nullable). This creates an inconsistency where the property signature suggests it's always non-null, but the default value can be null.

Consider either:

  1. Making the property nullable: public partial Action? OnTappingOutsideOfPopup { get; set; }
  2. Providing a non-null default value if the property should never be null

Note: The interface IPopupOptions.OnTappingOutsideOfPopup is nullable (Action?), so option 1 is recommended for consistency.

Copilot uses AI. Check for mistakes.
public static readonly BindableProperty PageOverlayColorProperty = BindableProperty.Create(nameof(PageOverlayColor), typeof(Color), typeof(PopupOptions), Options.DefaultPopupOptionsSettings.PageOverlayColor);
[BindableProperty(DefaultValueCreatorMethodName = nameof(CreatePageOverlayColor))]
public partial Color PageOverlayColor { get; set; }
static object CreatePageOverlayColor(BindableObject? _) => Options.DefaultPopupOptionsSettings.PageOverlayColor;
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Nullability mismatch: The property is declared as non-nullable Color, but the default value creator method can potentially return a nullable value if Options.DefaultPopupOptionsSettings.PageOverlayColor is null. While Color is a struct and typically non-nullable, this could cause issues if the default settings are not properly initialized.

Verify that Options.DefaultPopupOptionsSettings.PageOverlayColor is guaranteed to be non-null, or update the default value creator to handle potential null cases explicitly.

Suggested change
static object CreatePageOverlayColor(BindableObject? _) => Options.DefaultPopupOptionsSettings.PageOverlayColor;
static object CreatePageOverlayColor(BindableObject? _)
{
return Options.DefaultPopupOptionsSettings.PageOverlayColor is not null
? Options.DefaultPopupOptionsSettings.PageOverlayColor
: Colors.Transparent;
}

Copilot uses AI. Check for mistakes.
@@ -1,3 +1,4 @@
using System.ComponentModel;
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The using System.ComponentModel; directive doesn't appear to be used in this file. The [BindableProperty] attribute is defined in the CommunityToolkit.Maui namespace (auto-generated by the source generator), not System.ComponentModel.

If this directive is not used elsewhere in the file, consider removing it to keep imports clean.

Suggested change
using System.ComponentModel;

Copilot uses AI. Check for mistakes.
Updated the `CanBeDismissedByTappingOutsideOfPopup` property to use a `DefaultValueCreatorMethodName` for dynamic default value resolution. Added the `CreateCanBeDismissedByTappingOutsideOfPopup` method to provide the default value at runtime, improving flexibility and reducing reliance on hardcoded defaults.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant