Skip to content
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
109 changes: 109 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue29458.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
x:Class="Maui.Controls.Sample.Issues.Issue29458">
<VerticalStackLayout>

<ScrollView
AutomationId="RTLScrollView"
x:Name="RTLScrollView"
Orientation="Horizontal"
FlowDirection="RightToLeft">
<HorizontalStackLayout>

<Border BackgroundColor="Red"
HeightRequest="48"
WidthRequest="200">
<Label Text="Tab1"
HorizontalOptions="Center"
VerticalOptions="Center"/>
</Border>

<Border BackgroundColor="Blue"
HeightRequest="48"
WidthRequest="200">
<Label Text="Tab2"
HorizontalOptions="Center"
VerticalOptions="Center"/>
</Border>

<Border BackgroundColor="Red"
HeightRequest="48"
WidthRequest="200">
<Label Text="Tab3"
HorizontalOptions="Center"
VerticalOptions="Center"/>
</Border>

<Border BackgroundColor="Blue"
HeightRequest="48"
WidthRequest="200">
<Label Text="Tab4"
HorizontalOptions="Center"
VerticalOptions="Center"/>
</Border>


<Border BackgroundColor="Red"
HeightRequest="48"
WidthRequest="200">
<Label Text="Tab5"
AutomationId="Tab5RTL"
HorizontalOptions="Center"
VerticalOptions="Center"/>
</Border>
</HorizontalStackLayout>
</ScrollView>

<ScrollView
AutomationId="LTRScrollView"
x:Name="LTRScrollView"
Orientation="Horizontal"
FlowDirection="LeftToRight">
<HorizontalStackLayout>

<Border BackgroundColor="Red"
HeightRequest="48"
WidthRequest="200">
<Label Text="Tab1"
HorizontalOptions="Center"
VerticalOptions="Center"/>
</Border>

<Border BackgroundColor="Blue"
HeightRequest="48"
WidthRequest="200">
<Label Text="Tab2"
HorizontalOptions="Center"
VerticalOptions="Center"/>
</Border>

<Border BackgroundColor="Red"
HeightRequest="48"
WidthRequest="200">
<Label Text="Tab3"
HorizontalOptions="Center"
VerticalOptions="Center"/>
</Border>

<Border BackgroundColor="Blue"
HeightRequest="48"
WidthRequest="200">
<Label Text="Tab4"
HorizontalOptions="Center"
VerticalOptions="Center"/>
</Border>

<Border BackgroundColor="Red"
HeightRequest="48"
WidthRequest="200">
<Label Text="Tab5"
AutomationId="Tab5LTR"
HorizontalOptions="Center"
VerticalOptions="Center"/>
</Border>
</HorizontalStackLayout>
</ScrollView>
</VerticalStackLayout>
</ContentPage>
10 changes: 10 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue29458.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 29458, "ScrollView content offset shifts unexpectedly when FlowDirection is set to RightToLeft")]
public partial class Issue29458 : ContentPage
{
public Issue29458()
{
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue29458 : _IssuesUITest
{
public Issue29458(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "ScrollView content offset shifts unexpectedly when FlowDirection is set to RightToLeft";

[Test]
[Category(UITestCategories.ScrollView)]
public void ScrollViewShouldWorkInRTL()
{
App.WaitForElement("RTLScrollView");
for (int i = 0; i < 3; i++)
{
App.ScrollLeft("RTLScrollView");
App.ScrollRight("LTRScrollView");
}
App.WaitForElement("Tab5RTL");
App.WaitForElement("Tab5LTR");
}
}
14 changes: 14 additions & 0 deletions src/Core/src/Platform/iOS/MauiScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ public override void LayoutSubviews()
var crossPlatformContentSize = crossPlatformLayout.CrossPlatformArrange(new Rect(new Point(), crossPlatformBounds));
var contentSize = crossPlatformContentSize.ToCGSize();

Comment thread
mattleibow marked this conversation as resolved.
// For Right-To-Left (RTL) layouts, we need to adjust the content arrangement and offset
// to ensure the content is correctly aligned and scrolled. This involves a second layout
// arrangement with an adjusted starting point and recalculating the content offset.
if (EffectiveUserInterfaceLayoutDirection == UIUserInterfaceLayoutDirection.RightToLeft)
{
var horizontalOffset = contentSize.Width - crossPlatformBounds.Width;
crossPlatformLayout.CrossPlatformArrange(new Rect(new Point(-horizontalOffset, 0), crossPlatformBounds));
ContentOffset = new CGPoint(horizontalOffset, 0);
Comment thread
mattleibow marked this conversation as resolved.
}
else
{
ContentOffset = CGPoint.Empty;
}

// When the content size changes, we need to adjust the scrollable area size so that the content can fit in it.
if (ContentSize != contentSize)
{
Expand Down