Skip to content
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

fix: make the counterAxisAlignment retro compatible #1006

Merged
merged 1 commit into from
Jan 17, 2024
Merged
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
2 changes: 1 addition & 1 deletion doc/controls/AutoLayoutControl.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Orientation | `Orientation` | Gets or sets the dimension by which the items are
Spacing | `double` | Gets or sets a uniform distance (in pixels) between stacked items. It is applied in the direction of the `AutoLayout`'s Orientation
Justify | `AutoLayoutJustify` | Gets or sets the value to determine how items are justified within the container. Options are `Stack` or `SpaceBetween`. Note: if a child has its `PrimaryAlignment` set to `Stretch`, it will default to `Stack`
PrimaryAxisAlignment | `AutoLayoutAlignment` | Gets or sets the alignment characteristics that are applied to the content, based on the value of the `Orientation` property. Options are `Start`, `Center`, and `End`. The default is `Start`.
CounterAxisAlignment | `AutoLayoutAlignment` | Gets or sets the alignment characteristics that are applied to the content, based on the inverse value of the `Orientation` property. Options are `Start`, `Center`, and `End`. The default is `Start`. If already set in `CounterAlignment` CounterAlignment will have priority.
CounterAxisAlignment | `AutoLayoutAlignment` | Gets or sets the alignment characteristics that are applied to the content, based on the inverse value of the `Orientation` property. Options are `Start`, `Center`, `End` and `Stretch`. The default is `Stretch`. If already set in `CounterAlignment` CounterAlignment will have priority.
IsReverseZIndex | `bool` | Gets or sets whether or not the ZIndex of the children should be reversed. The default is `false`
Padding | `Thickness` | **WARNING:** Padding for `AutoLayout` behaves the same as it does within the Figma Plugin: The anchor points determine which sides of the Padding will be taken into consideration. For example, items that are aligned to the Right and Top positions will only take the `Tickness.Right` and `Thickness.Top` values of `Padding` into consideration

Expand Down
12 changes: 10 additions & 2 deletions src/Uno.Toolkit.RuntimeTests/Tests/AutoLayoutTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,9 @@ public async Task When_Hug_With_Padding_CounterAxis()

[TestMethod]
[RequiresFullWindow]
public async Task When_CounterAlignment_stretch()
[DataRow(false)]
[DataRow(true)]
public async Task When_CounterAlignment_stretch(bool isLegacy)
{
var SUT = new AutoLayout()
{
Expand All @@ -748,7 +750,13 @@ public async Task When_CounterAlignment_stretch()
};

AutoLayout.SetPrimaryAlignment(rectangle, AutoLayoutPrimaryAlignment.Stretch);
AutoLayout.SetCounterAlignment(rectangle, AutoLayoutAlignment.Stretch);

if (isLegacy is false)
{
//If not legacy CounterAxisAlignment should always be defined.
SUT.CounterAxisAlignment = AutoLayoutAlignment.Start;
AutoLayout.SetCounterAlignment(rectangle, AutoLayoutAlignment.Stretch);
}

SUT.Children.Add(rectangle);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,10 @@ protected override Size ArrangeOverride(Size finalSize)
EnsureZeroFloor(ref childLength);

// Calculate the position of the child by applying the alignment instructions
var counterA = child.Element.ReadLocalValue(CounterAlignmentProperty);
var isCounterAlignemntDefined = counterA != DependencyProperty.UnsetValue;
var isCounterAlignemntDefined = child.Element.ReadLocalValue(CounterAlignmentProperty) as AutoLayoutAlignment? is { };

var childCounterAlignment = GetCounterAlignment(child.Element);
var isStretch = childCounterAlignment is AutoLayoutAlignment.Stretch;
var useCounterAxisAlignement = isStretch || !isCounterAlignemntDefined;
var counterAlignment = useCounterAxisAlignement ? this.CounterAxisAlignment : childCounterAlignment;
var counterAlignment = !isCounterAlignemntDefined ? this.CounterAxisAlignment : GetCounterAlignment(child.Element);
var isStretch = counterAlignment is AutoLayoutAlignment.Stretch;
var haveCounterStartPadding = isStretch || counterAlignment is AutoLayoutAlignment.Start;
var counterStartPadding = haveCounterStartPadding ? (isHorizontal ? padding.Top : padding.Left) : 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ private void ApplyMinMaxValues(ref Size desiredSize)

if (child as FrameworkElement is { } frameworkElement)
{
var test = frameworkElement.ReadLocalValue(CounterAlignmentProperty) == DependencyProperty.UnsetValue ? counterAxisAlignment : GetCounterAlignment(child);
var counterAlignment = frameworkElement.ReadLocalValue(CounterAlignmentProperty) == DependencyProperty.UnsetValue ? counterAxisAlignment : GetCounterAlignment(child);

UpdateCounterAlignment(ref frameworkElement, isOrientationHorizontal, isPrimaryAlignmentStretch, test);
UpdateCounterAlignment(ref frameworkElement, isOrientationHorizontal, isPrimaryAlignmentStretch, counterAlignment);

var isStretch = isOrientationHorizontal ?
frameworkElement.VerticalAlignment is VerticalAlignment.Stretch :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public AutoLayoutAlignment PrimaryAxisAlignment
nameof(CounterAxisAlignment),
typeof(AutoLayoutAlignment),
typeof(AutoLayout),
new PropertyMetadata(default(AutoLayoutAlignment), propertyChangedCallback: InvalidateArrangeCallback));
new PropertyMetadata(AutoLayoutAlignment.Stretch, propertyChangedCallback: InvalidateArrangeCallback));

public AutoLayoutAlignment CounterAxisAlignment
{
Expand Down Expand Up @@ -111,14 +111,14 @@ public static AutoLayoutPrimaryAlignment GetPrimaryAlignment(DependencyObject el
}

// -- CounterAlignment Attached Property --
//[DynamicDependency(nameof(GetCounterAlignment))]
[DynamicDependency(nameof(GetCounterAlignment))]
public static readonly DependencyProperty CounterAlignmentProperty = DependencyProperty.RegisterAttached(
"CounterAlignment",
typeof(AutoLayoutAlignment),
typeof(AutoLayout),
new PropertyMetadata(default(AutoLayoutAlignment), propertyChangedCallback: InvalidateArrangeCallback));

//[DynamicDependency(nameof(GetCounterAlignment))]
[DynamicDependency(nameof(GetCounterAlignment))]
public static void SetCounterAlignment(DependencyObject element, AutoLayoutAlignment value)
{
element.SetValue(CounterAlignmentProperty, value);
Expand Down
Loading