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 RTL in AbsoluteLayout #7309

Merged
merged 8 commits into from May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/Core/src/Layouts/AbsoluteLayoutManager.cs
Expand Up @@ -60,11 +60,17 @@ public override Size ArrangeChildren(Rect bounds)
{
var padding = AbsoluteLayout.Padding;

double top = padding.Top + bounds.Y;
double left = padding.Left + bounds.X;
double top = padding.Top + bounds.Top;
double left = padding.Left + bounds.Left;
double right = bounds.Right - padding.Right;
double availableWidth = bounds.Width - padding.HorizontalThickness;
double availableHeight = bounds.Height - padding.VerticalThickness;

bool leftToRight = AbsoluteLayout.ShouldArrangeLeftToRight();

// Figure out where we're starting from (the left edge of the padded area, or the right edge)
double xPosition = leftToRight ? left : right;
hartez marked this conversation as resolved.
Show resolved Hide resolved

for (int n = 0; n < AbsoluteLayout.Count; n++)
{
var child = AbsoluteLayout[n];
Expand Down Expand Up @@ -93,7 +99,11 @@ public override Size ArrangeChildren(Rect bounds)
destination.Y = (availableHeight - destination.Height) * destination.Y;
}

destination.X += left;
if (leftToRight)
destination.X += left;
else
destination.X = right - destination.X - destination.Width;

destination.Y += top;

child.Arrange(destination);
Expand Down
42 changes: 42 additions & 0 deletions src/Core/tests/UnitTests/Layouts/AbsoluteLayoutManagerTests.cs
Expand Up @@ -445,5 +445,47 @@ public void ChildMeasureRespectsProportionalBounds()

child.Received().Measure(Arg.Is(expectedWidth * widthConstraint), Arg.Is(expectedHeight * heightConstraint));
}

[Fact(DisplayName = "First View in LTR Absolute Layout is on the left")]
public void LtrShouldHaveFirstItemOnTheLeft()
{
var abs = CreateTestLayout();
var child = CreateTestView();
SubstituteChildren(abs, child);
var childBounds = new Rect(10, 0, 100, 100);
SetLayoutBounds(abs, child, childBounds);

abs.FlowDirection.Returns(FlowDirection.LeftToRight);

var manager = new AbsoluteLayoutManager(abs);
var measuredSize = manager.Measure(double.PositiveInfinity, 100);
manager.ArrangeChildren(new Rect(Point.Zero, measuredSize));

// We expect that the view should be arranged on the left
var expectedRectangle = new Rect(10, 0, 100, 100);

abs[0].Received().Arrange(Arg.Is(expectedRectangle));
}

[Fact(DisplayName = "First View in RTL Absolute Layout is on the right")]
public void RtlShouldHaveFirstItemOnTheRight()
{
var abs = CreateTestLayout();
var child = CreateTestView();
SubstituteChildren(abs, child);
var childBounds = new Rect(10, 0, 100, 100);
SetLayoutBounds(abs, child, childBounds);

abs.FlowDirection.Returns(FlowDirection.RightToLeft);

var manager = new AbsoluteLayoutManager(abs);
var measuredSize = manager.Measure(double.PositiveInfinity, 100);
manager.ArrangeChildren(new Rect(Point.Zero, measuredSize));

// We expect that the view should be arranged on the right
var expectedRectangle = new Rect(0, 0, 100, 100);

abs[0].Received().Arrange(Arg.Is(expectedRectangle));
}
}
}