Remove BindablePropertyAttribute.DefaultValue#2995
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ui into feature/bp-sourcegen-init
…nly BindableProperty. Extend unit test.
…alizer implementation.
…tDefaultValueCreatorMethodName method)
…faultValueCreatorMethodName for clarity
…eratesCorrectCode
…fault_GeneratedCodeDefaultsToUseDefaultValueCreatorMethod`
|
Do we want to add tests for most common system types that we will see used? Like |
This reverts commit b84522e.
…ps://github.com/CommunityToolkit/Maui into Remove-`BindablePropertyAttribute.DefaultValue`
…ps://github.com/CommunityToolkit/Maui into Remove-`BindablePropertyAttribute.DefaultValue`
@ne0rrmatrix Done! I've added these to this Unit Test: |
src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/GestureManager.shared.cs
Show resolved
Hide resolved
ne0rrmatrix
left a comment
There was a problem hiding this comment.
This was amazing. Learned a few new things reading this PR. It is exactly as discussed in this months meeting and is exactly what we are looking for. Very good job. I have just that one question about how we are handling touch behavior null issue that I mentioned. If you feel it is a non issue I think we can go ahead and merge this. I am excited to see this one get added!
It fixes the one issue I was struggling with and solves a few others with regards to default values.
Description of Change
This PR removes the
DefaultValueproperty from[BindableProperty]for the following reasons now that it is not longer required thanks to #2987:DefaultValuehas been the largest source of pain and workarounds inBindablePropertySourceGeneratorDefaultValueproperty only supported compile-time constants, while partial property initializer can use static readonly values[BindableProperty(DefaultValue = Colors.Transparent)]would generate a compiler error becauseColors.Transparentispublic static readonlyBindablePropertyAttribute.DefaultValue, we would need to write an additional Analyzer to generate a compiler error when we detect a developer is using bothDefaultValueand the partial property initializerPR Checklist
mainat time of PRAdditional information
TouchBehaviorRefactoringI refactored TouchBehavior's properties to be
nullby default so that we can determine whether or not a developer as set each property.I was forced into this refactor because the underlying
GestureManagerwas relying onBindableProeprety.IsSetto determine whether or not a developer had set a value. This logic only works withBindableProperty.DefaultValue. Now that partial property initializers useDefaultValueCreator,BindableProperty.IsSetalways returnedfalseuntil .NET MAUI only callsDefaultValueCreatorwhen theBindablePropertyis first accessed (e.g.BindableProperty.GetValue(DefaultOpacityProperty).This refactor of TouchBehavior should not cause any breaking changes for developers, as noted by the fact that I did not need to modify any of the following code:
ImageTouchBehavior Refactoring
I also refactored
ImageTouchBehavior(same reasons asTouchBehavior).This refactor required adding an OnPropertyChanged method for
DefaultImageSource,HoveredImageSourceandPressedImageSourceto support the scenario where theImageSource?was set tonullwhen the image was active.This refactor of TouchBehavior should not cause any breaking changes for developers, as noted by the fact that I did not need to modify any of the following code:
ImageTouchBehaviorTests .VerifyImageSourceStateMachineImageTouchBehaviorTests .VerifyImageSourceStateMachineWhenImageSourceSetToNullWhilstActive