Skip to content

Commit

Permalink
fix!: Remove [Get|Set][Left|Top|ZIndex] methods that take Dependenc…
Browse files Browse the repository at this point in the history
…yObject from `Canvas`

BREAKING CHANGE: `GetLeft`, `GetTop`, `SetLeft`, `SetTop`, `GetZIndex`, and `SetZIndex` overloads that take DependencyObject are now removed. The UIElement overloads should be used instead.
  • Loading branch information
Youssef1313 committed Feb 23, 2023
1 parent a13f425 commit ae28f15
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 31 deletions.
6 changes: 6 additions & 0 deletions build/PackageDiffIgnore.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9463,6 +9463,12 @@
<Member fullName="System.Void Windows.UI.Xaml.Controls.Primitives.Popup.OnVerticalOffsetChanged(System.Double oldVerticalOffset, System.Double newVerticalOffset)" reason="Api alignments" />
<Member fullName="System.Void Windows.UI.Xaml.Controls.RelativePanel.SetRightOf(Windows.UI.Xaml.UIElement view, System.Object value)" reason="Api alignments" />
<Member fullName="System.Void Windows.UI.Xaml.Controls.WebView.NavigateWithHttpRequestMessage(System.Net.Http.HttpRequestMessage requestMessage)" reason="Api alignments" />
<Member fullName="System.Double Windows.UI.Xaml.Controls.Canvas.GetLeft(Windows.UI.Xaml.DependencyObject obj)" reason="Api alignments" />
<Member fullName="System.Void Windows.UI.Xaml.Controls.Canvas.SetLeft(Windows.UI.Xaml.DependencyObject obj, System.Double value)" reason="Api alignments" />
<Member fullName="System.Double Windows.UI.Xaml.Controls.Canvas.GetTop(Windows.UI.Xaml.DependencyObject obj)" reason="Api alignments" />
<Member fullName="System.Void Windows.UI.Xaml.Controls.Canvas.SetTop(Windows.UI.Xaml.DependencyObject obj, System.Double value)" reason="Api alignments" />
<Member fullName="System.Double Windows.UI.Xaml.Controls.Canvas.GetZIndex(Windows.UI.Xaml.DependencyObject obj)" reason="Api alignments" />
<Member fullName="System.Void Windows.UI.Xaml.Controls.Canvas.SetZIndex(Windows.UI.Xaml.DependencyObject obj, System.Double value)" reason="Api alignments" />
</Methods>
</IgnoreSet>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void When_CanvasPropertyConvert()
Assert.AreEqual(42d, SUT.GetValue(Canvas.TopProperty));

SUT.SetValue(Canvas.ZIndexProperty, "42");
Assert.AreEqual(42d, SUT.GetValue(Canvas.ZIndexProperty));
Assert.AreEqual(42, SUT.GetValue(Canvas.ZIndexProperty));
}
}
}
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/Canvas/Canvas.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ partial void MeasureOverridePartial()

var sorted = Children
.Select((view, childrenIndex) => (view, childrenIndex))
.OrderBy(tpl => tpl.view is DependencyObject obj ? Canvas.GetZIndex(obj) : 0); // Note: this has to be a stable sort
.OrderBy(tpl => tpl.view is UIElement obj ? Canvas.GetZIndex(obj) : 0); // Note: this has to be a stable sort

var drawOrder = 0;
foreach (var tpl in sorted)
Expand Down
8 changes: 4 additions & 4 deletions src/Uno.UI/UI/Xaml/Controls/Canvas/Canvas.Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ protected override Size ArrangeOverride(Size finalSize)
{
if (child is _View childView)
{
var childAsDO = child as DependencyObject;
var childAsUIElement = child as UIElement;
var desiredSize = GetElementDesiredSize(childView);

var childRect = new Rect
{
X = GetLeft(childAsDO),
Y = GetTop(childAsDO),
X = GetLeft(childAsUIElement),
Y = GetTop(childAsUIElement),
Width = desiredSize.Width,
Height = desiredSize.Height,
};

#if __IOS__
child.Layer.ZPosition = (nfloat)GetZIndex(childAsDO);
child.Layer.ZPosition = (nfloat)GetZIndex(childAsUIElement);
#endif

ArrangeElement(child, childRect);
Expand Down
31 changes: 6 additions & 25 deletions src/Uno.UI/UI/Xaml/Controls/Canvas/Canvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ public partial class Canvas : Panel
{
#region Left

public static double GetLeft(DependencyObject obj)
=> GetLeftValue(obj);

public static void SetLeft(DependencyObject obj, double value)
=> SetLeftValue(obj, value);


[GeneratedDependencyProperty(DefaultValue = 0.0d, AttachedBackingFieldOwner = typeof(UIElement), Attached = true, Options = FrameworkPropertyMetadataOptions.AutoConvert | FrameworkPropertyMetadataOptions.AffectsArrange)]
public static DependencyProperty LeftProperty { get; } = CreateLeftProperty();

Expand All @@ -51,12 +44,6 @@ private static void OnLeftChanged(DependencyObject dependencyObject, DependencyP

#region Top

public static double GetTop(DependencyObject obj)
=> GetTopValue(obj);

public static void SetTop(DependencyObject obj, double value)
=> SetTopValue(obj, value);

[GeneratedDependencyProperty(DefaultValue = 0.0d, AttachedBackingFieldOwner = typeof(UIElement), Attached = true, Options = FrameworkPropertyMetadataOptions.AutoConvert | FrameworkPropertyMetadataOptions.AffectsArrange)]
public static DependencyProperty TopProperty { get; } = CreateTopProperty();

Expand All @@ -79,12 +66,6 @@ private static void OnTopChanged(DependencyObject dependencyObject, DependencyPr

#region ZIndex

public static double GetZIndex(DependencyObject obj)
=> GetZIndexValue(obj);

public static void SetZIndex(DependencyObject obj, double value)
=> SetZIndexValue(obj, value);

[GeneratedDependencyProperty(DefaultValue = 0.0d, AttachedBackingFieldOwner = typeof(UIElement), Attached = true, Options = FrameworkPropertyMetadataOptions.AutoConvert)]
public static DependencyProperty ZIndexProperty { get; } = CreateZIndexProperty();

Expand All @@ -111,16 +92,16 @@ public Canvas()

partial void InitializePartial();

public static double GetLeft(global::Windows.UI.Xaml.UIElement element) => GetLeft((DependencyObject)element);
public static double GetLeft(global::Windows.UI.Xaml.UIElement element) => GetLeftValue(element);

public static void SetLeft(global::Windows.UI.Xaml.UIElement element, double length) => SetLeft((DependencyObject)element, length);
public static void SetLeft(global::Windows.UI.Xaml.UIElement element, double length) => SetLeftValue(element, length);

public static double GetTop(global::Windows.UI.Xaml.UIElement element) => GetTop((DependencyObject)element);
public static double GetTop(global::Windows.UI.Xaml.UIElement element) => GetTopValue(element);

public static void SetTop(global::Windows.UI.Xaml.UIElement element, double length) => SetTop((DependencyObject)element, length);
public static void SetTop(global::Windows.UI.Xaml.UIElement element, double length) => SetTopValue(element, length);

public static int GetZIndex(global::Windows.UI.Xaml.UIElement element) => (int)GetZIndex((DependencyObject)element);
public static int GetZIndex(global::Windows.UI.Xaml.UIElement element) => GetZIndexValue(element);

public static void SetZIndex(global::Windows.UI.Xaml.UIElement element, int value) => SetZIndex((DependencyObject)element, value);
public static void SetZIndex(global::Windows.UI.Xaml.UIElement element, int value) => SetZIndexValue(element, value);
}
}

0 comments on commit ae28f15

Please sign in to comment.