Skip to content

Bindable property for camera view#2974

Merged
TheCodeTraveler merged 17 commits intoCommunityToolkit:mainfrom
ne0rrmatrix:BindablePropertyForCameraView
Dec 2, 2025
Merged

Bindable property for camera view#2974
TheCodeTraveler merged 17 commits intoCommunityToolkit:mainfrom
ne0rrmatrix:BindablePropertyForCameraView

Conversation

@ne0rrmatrix
Copy link
Member

This pull request refactors the way bindable properties are declared and implemented in the CameraView class, moving from manual property and backing field declarations to using the [BindableProperty] attribute for automatic generation. This modernizes the codebase, reduces boilerplate, and makes the property definitions more concise and maintainable. Additionally, a project reference is added for source generators, and some minor code cleanups are performed.

Key changes include:

Bindable Property Refactoring:

  • Replaced manual declaration of bindable properties in CameraView (such as IsAvailable, CameraFlashMode, IsTorchOn, etc.) with the [BindableProperty] attribute, allowing source generators to auto-generate the necessary code. This change significantly reduces boilerplate and improves maintainability.
  • Removed the corresponding explicit property implementations and backing fields for these bindable properties, as they are now generated automatically.

Project and Code Cleanup:

  • Added a project reference to CommunityToolkit.Maui.SourceGenerators.Internal as an analyzer in the .csproj file, enabling the use of source generators for bindable properties.
  • Removed unnecessary public modifier from the CameraViewDefaults class, making it internal to the assembly.
  • Cleaned up unused using directives in CameraView.shared.cs. ### Description of Change ###

PR Checklist

Additional information

This is blocked until #2933 merges. It requires support for BindableProperties.CreateReadOnly which is introduced in that PR. See here: https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.controls.bindableproperty.createreadonly?view=net-maui-10.0

Copilot AI review requested due to automatic review settings November 30, 2025 07:56
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 PR modernizes the CameraView class by refactoring manual bindable property declarations to use the [BindableProperty] attribute with source generators, significantly reducing boilerplate code. The changes include adding source generator support, updating property definitions to use attributes, removing redundant property implementations, and adjusting the visibility of the CameraViewDefaults class to internal.

Key changes:

  • Replaced manual BindableProperty.Create and BindableProperty.CreateReadOnly calls with [BindableProperty] attributes for all properties in CameraView
  • Added project reference to CommunityToolkit.Maui.SourceGenerators.Internal as an analyzer
  • Changed CameraViewDefaults visibility from public to internal, as it's marked with [EditorBrowsable(EditorBrowsableState.Never)]

Reviewed changes

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

File Description
src/CommunityToolkit.Maui.Camera/Views/CameraView.shared.cs Refactored all bindable properties to use [BindableProperty] attributes, removed manual property implementations, and cleaned up unused using directives
src/CommunityToolkit.Maui.Camera/Primitives/CameraViewDefaults.shared.cs Changed class visibility from public to internal to properly hide implementation details
src/CommunityToolkit.Maui.Camera/CommunityToolkit.Maui.Camera.csproj Added source generator project reference as an analyzer to enable automatic bindable property generation

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Copilot AI review requested due to automatic review settings December 2, 2025 18:51
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI review requested due to automatic review settings December 2, 2025 19: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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI review requested due to automatic review settings December 2, 2025 19:38
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@TheCodeTraveler TheCodeTraveler marked this pull request as ready for review December 2, 2025 19:38
@TheCodeTraveler TheCodeTraveler added breaking change This label is used for PRs that include a breaking change and removed blocked labels Dec 2, 2025
Copilot AI review requested due to automatic review settings December 2, 2025 20:00
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Collaborator

@TheCodeTraveler TheCodeTraveler left a comment

Choose a reason for hiding this comment

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

Thanks James!

Just FYI - I fixed the XML docs and moved <EmitCompilerGeneratedFiles> to Directory.Build.props to avoid us duplicating it in every .csproj file

@TheCodeTraveler TheCodeTraveler merged commit 4ed306b into CommunityToolkit:main Dec 2, 2025
10 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

breaking change This label is used for PRs that include a breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants