[Enhancement] We need a way to see if a property was set (perf & defaults)
See original GitHub issueDescription
Initially this was just an issue for bad padding logic, however, this does expose a bigger issue: we have no way of actually knowing if a property was set.
This has 2 major benefits:
- Performance: no use setting a value to the default when not doing anything is cheaper
- Default: if nothing was set, then we are using default
An added bonus is if there is a way to unset a value and revert to OS defaults.
Maybe this is as simple as having a nullable properties on IView
:
interface IView
{
Thickness? Padding { get; }
IBrush? Background { get; }
}
**SEMI-OLD COMMENT**
```csharp
interface IView
{
IBrush Background { get; }
Thickness Padding { get; }
bool IsSet(string property);
}
The default implementation for say Controls could be:
class View : IView
{
BindableProperty BackgroundProperty = BindablePropert.Create();
IBrush Background => GetValue(BackgroundProperty);
Thickness Padding => GetValue(PaddingProp);
bool IsSet(string property)
{
if (property == BackgroundProperty.Name)
return IsSet(BackgroundProperty);
return true;
}
}
OLD COMMENT
Button padding logic is incorrect.
On iOS, there is no default padding so this is not an issue. On Windows and Android, there is a default padding based on various factors. Windows is just a nice padding, but Android has this related to the drawable. However, since we implemented padding, all this goes away and we just wing it. Android ignores the padding, and since we always set it, there is never any padding. Windows tried to keep it as a base, but now we will always have a padding - even when set to 0.
Not sure what the solution is here, since all we have is a double
and all values are valid - unless we say that all padding >= 0 and thus a negative padding == default? Will this break old renderers? Is a negative padding valid - like the content must hang over the edge of the control? If we go with -1 == default and somebody doesn’t like it, they can always override this method…
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Comet uses nulls. If null, reset the value. I am not a fan of
IsSet(string property)
All of our structs have a default value as well. If not, lets make them nullable.I also realise that padding is a
Thickness
, so we could add aNaN
just like there is forZero
. And if you want a default for just one side, you can set that. This will also work for things like corner radius and pretty much most things 😃