Bindable property for camera view#2974
Bindable property for camera view#2974TheCodeTraveler merged 17 commits intoCommunityToolkit:mainfrom
Conversation
Do not merge until after CommunityToolkit#2933 is merged
Was using `DefaultValue` Incorrectly
There was a problem hiding this comment.
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.CreateandBindableProperty.CreateReadOnlycalls with[BindableProperty]attributes for all properties inCameraView - Added project reference to
CommunityToolkit.Maui.SourceGenerators.Internalas an analyzer - Changed
CameraViewDefaultsvisibility 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.
TheCodeTraveler
left a comment
There was a problem hiding this comment.
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
This pull request refactors the way bindable properties are declared and implemented in the
CameraViewclass, 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:
CameraView(such asIsAvailable,CameraFlashMode,IsTorchOn, etc.) with the[BindableProperty]attribute, allowing source generators to auto-generate the necessary code. This change significantly reduces boilerplate and improves maintainability.Project and Code Cleanup:
CommunityToolkit.Maui.SourceGenerators.Internalas an analyzer in the.csprojfile, enabling the use of source generators for bindable properties.publicmodifier from theCameraViewDefaultsclass, making it internal to the assembly.usingdirectives inCameraView.shared.cs. ### Description of Change ###PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information
This is blocked until #2933 merges. It requires support for
BindableProperties.CreateReadOnlywhich 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