Skip to content

Avoid redundant property round-trips between platform and xplat across multiple controls #29970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Controls/src/Core/Element/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,14 @@ private protected override void OnBindablePropertySet(BindableProperty property,

base.OnBindablePropertySet(property, original, value, changed, willFirePropertyChanged);
_pendingHandlerUpdatesFromBPSet.Remove(property.PropertyName);
UpdateHandlerValue(property.PropertyName, changed);

var specificity = GetContext(property).Values.GetSpecificity();
if (specificity == SetterSpecificity.FromHandler)
{
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@StephaneDelcroix
Currently, SetterSpecificity.FromHandler is used in several places where the value is not actually coming from the handler, and this is blocking what we're trying to achieve here.

Here are the locations where it's used:

public void SetBinding(BindableProperty targetProperty, BindingBase binding)
=> SetBinding(targetProperty, binding, binding != null && targetProperty != null && binding.GetRealizedMode(targetProperty) == BindingMode.TwoWay ? SetterSpecificity.FromHandler : SetterSpecificity.FromBinding);

// support normal/code properties
self.SetValue(property, value, SetterSpecificity.FromHandler);

Wouldn't it make more sense to introduce a separate, low-priority fallback specificity for these cases instead of overloading FromHandler, which is intended for platform-set values?

Copy link
Member

Choose a reason for hiding this comment

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

@StephaneDelcroix thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

the new name is very confusing. could you pick a good, self-explanatory one, so we know what this is supposed to do when we come back here next time ?

}

UpdateHandlerValue(property.PropertyName, changed);
}

/// <summary>Method that is called when a bound property is changed.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ void UpdateVirtualSingleSelection()
if (ItemsView != null)
{
_ignoreVirtualSelectionChange = true;
ItemsView.SelectedItem = selectedItem;
ItemsView.SetValueFromRenderer(SelectableItemsView.SelectedItemProperty, selectedItem);


_ignoreVirtualSelectionChange = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ void FormsSelectItem(NSIndexPath indexPath)
case SelectionMode.None:
break;
case SelectionMode.Single:
ItemsView.SelectedItem = GetItemAtIndex(indexPath);
var item = GetItemAtIndex(indexPath);
ItemsView.SetValueFromRenderer(SelectableItemsView.SelectedItemsProperty,item);
break;
case SelectionMode.Multiple:
ItemsView.SelectedItems.Add(GetItemAtIndex(indexPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ void FormsSelectItem(NSIndexPath indexPath)
case SelectionMode.None:
break;
case SelectionMode.Single:
ItemsView.SelectedItem = GetItemAtIndex(indexPath);
var item = GetItemAtIndex(indexPath);
ItemsView.SetValueFromRenderer(SelectableItemsView.SelectedItemsProperty,item);
break;
case SelectionMode.Multiple:
ItemsView.SelectedItems.Add(GetItemAtIndex(indexPath));
Expand Down
6 changes: 6 additions & 0 deletions src/Controls/src/Core/Slider/Slider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ public double Value
set { SetValue(ValueProperty, value); }
}

double IRange.Value
{
get => Value;
set => SetValue(ValueProperty, value, SetterSpecificity.FromHandler);
}

public event EventHandler<ValueChangedEventArgs> ValueChanged;
public event EventHandler DragStarted;
public event EventHandler DragCompleted;
Expand Down
6 changes: 6 additions & 0 deletions src/Controls/src/Core/Stepper/Stepper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ public double Value

double IStepper.Interval => Increment;

double IRange.Value
{
get => Value;
set => SetValue(ValueProperty, value, SetterSpecificity.FromHandler);
}

private protected override string GetDebuggerDisplay()
{
return $"{base.GetDebuggerDisplay()}, Value = {Value}";
Expand Down