Skip to content

Commit

Permalink
[C] SetterSpecificity
Browse files Browse the repository at this point in the history
each SetValue call has a specificity, and the specificity can be used to
determine which value needs to be applied/unapplied/restored
  • Loading branch information
StephaneDelcroix committed May 16, 2023
1 parent c459b0d commit 6209314
Show file tree
Hide file tree
Showing 66 changed files with 921 additions and 550 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected virtual void InitializeElement(T element) { }
protected virtual void Build(StackLayout stackLayout)
{
var isFocusedView = new T();
isFocusedView.SetValueCore(IsFocusedPropertyKey, true);
isFocusedView.SetValue(IsFocusedPropertyKey, true, specificity: SetterSpecificity.FromHandler);

IsEnabledStateViewContainer = new StateViewContainer<T>(Test.VisualElement.IsEnabled, new T { IsEnabled = true });
IsEnabledStateViewContainer.StateChangeButton.Command = new Command(() =>
Expand All @@ -85,11 +85,11 @@ protected virtual void Build(StackLayout stackLayout)
if ((bool)isFocusedView.GetValue(VisualElement.IsFocusedProperty))
{
isFocusedView.SetValueCore(IsFocusedPropertyKey, false);
isFocusedView.SetValue(IsFocusedPropertyKey, false, specificity: SetterSpecificity.FromHandler);
}
else
{
isFocusedView.SetValueCore(IsFocusedPropertyKey, true);
isFocusedView.SetValue(IsFocusedPropertyKey, true, specificity: SetterSpecificity.FromHandler);
}
});

Expand Down
12 changes: 7 additions & 5 deletions src/Controls/src/Core/AppThemeBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class AppThemeBinding : BindingBase
WeakReference<BindableObject> _weakTarget;
BindableProperty _targetProperty;
bool _attached;
SetterSpecificity specificity;

internal override BindingBase Clone() => new AppThemeBinding
{
Expand All @@ -26,12 +27,13 @@ internal override void Apply(bool fromTarget)
SetAttached(true);
}

internal override void Apply(object context, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged = false)
internal override void Apply(object context, BindableObject bindObj, BindableProperty targetProperty, bool fromBindingContextChanged, SetterSpecificity specificity)
{
_weakTarget = new WeakReference<BindableObject>(bindObj);
_targetProperty = targetProperty;
base.Apply(context, bindObj, targetProperty, fromBindingContextChanged);
ApplyCore();
base.Apply(context, bindObj, targetProperty, fromBindingContextChanged, specificity);
this.specificity = specificity;
ApplyCore(false);
SetAttached(true);
}

Expand Down Expand Up @@ -59,7 +61,7 @@ void ApplyCore(bool dispatch = false)
else
Set();

void Set() => target.SetValueCore(_targetProperty, GetValue());
void Set() => target.SetValueCore(_targetProperty, GetValue(), Internals.SetValueFlags.ClearDynamicResource, BindableObject.SetValuePrivateFlags.Default | BindableObject.SetValuePrivateFlags.Converted, specificity);
}

object _light;
Expand Down Expand Up @@ -141,4 +143,4 @@ void SetAttached(bool value)
}
}
}
}
}
Loading

0 comments on commit 6209314

Please sign in to comment.