diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/RTLModePaddingShouldWork.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/RTLModePaddingShouldWork.png new file mode 100644 index 000000000000..a011cfe0a028 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/RTLModePaddingShouldWork.png differ diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/RightToLeftFlowDirectionShouldWork.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/RightToLeftFlowDirectionShouldWork.png index 0708ab4c9c15..9dbdd245c969 100644 Binary files a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/RightToLeftFlowDirectionShouldWork.png and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/RightToLeftFlowDirectionShouldWork.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue32316.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue32316.cs new file mode 100644 index 000000000000..af473e79626b --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue32316.cs @@ -0,0 +1,101 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 32316, "RTL mode: Padding for the label is not mirroring properly", PlatformAffected.iOS | PlatformAffected.Android)] +public class Issue32316 : ContentPage +{ + private readonly HorizontalStackLayout _row1; + private readonly HorizontalStackLayout _row2; + + public Issue32316() + { + var toggleButton = new Button + { + Text = "Toggle FlowDirection", + AutomationId = "ToggleFlowDirectionButton", + HorizontalOptions = LayoutOptions.Center + }; + + toggleButton.Clicked += OnToggleClicked; + + _row1 = BuildRow(); + _row2 = BuildRow(); + + Content = new VerticalStackLayout + { + Spacing = 12, + Padding = 12, + Children = + { + toggleButton, + _row1, + _row2, + } + }; + } + + private void OnToggleClicked(object sender, EventArgs e) + { + _row2.FlowDirection = FlowDirection.RightToLeft; + } + + private static HorizontalStackLayout BuildRow() + { + var stackLayout = new HorizontalStackLayout + { + HorizontalOptions = LayoutOptions.Center, + }; + + stackLayout.Children.Add(CreateIconBorder("✂")); + stackLayout.Children.Add(CreateIconBorder("✖")); + + return stackLayout; + } + + private static View CreateIconBorder(string icon) + { + return new Border + { + BackgroundColor = Colors.LightGray, + Stroke = Colors.Gray, + StrokeThickness = 1, + WidthRequest = 60, + HeightRequest = 40, + InputTransparent = true, + Content = CreateIconView(icon) + }; + } + + private static View CreateIconView(string icon) + { + var iconLabel = new Label + { + Text = icon, + FontSize = 16, + FontAutoScalingEnabled = false, + Padding = new Thickness(10, 0, 0, 0), + HorizontalOptions = LayoutOptions.Start, + VerticalOptions = LayoutOptions.Center, + VerticalTextAlignment = TextAlignment.Center, + BackgroundColor = Colors.Transparent, + HeightRequest = 40 + }; + + var dropDownLabel = new Label + { + Text = "V", + FontSize = 16, + Margin = new Thickness(0, 0, 10, 0), + FontFamily = "MauiMaterialAssets", + VerticalTextAlignment = TextAlignment.Center, + VerticalOptions = LayoutOptions.Center, + BackgroundColor = Colors.Transparent + }; + + return new HorizontalStackLayout + { + HorizontalOptions = LayoutOptions.Center, + HeightRequest = 40, + Children = { iconLabel, dropDownLabel } + }; + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/RTLModePaddingShouldWork.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/RTLModePaddingShouldWork.png new file mode 100644 index 000000000000..42959a38a772 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/RTLModePaddingShouldWork.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32316.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32316.cs new file mode 100644 index 000000000000..d3bf31669c26 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32316.cs @@ -0,0 +1,24 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue32316 : _IssuesUITest +{ + + public Issue32316(TestDevice testDevice) : base(testDevice) + { + } + + public override string Issue => "RTL mode: Padding for the label is not mirroring properly"; + + [Test] + [Category(UITestCategories.Label)] + public void RTLModePaddingShouldWork() + { + App.WaitForElement("ToggleFlowDirectionButton"); + App.Tap("ToggleFlowDirectionButton"); + VerifyScreenshot(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/RTLModePaddingShouldWork.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/RTLModePaddingShouldWork.png new file mode 100644 index 000000000000..0bc488eb1f83 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/RTLModePaddingShouldWork.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/RTLModePaddingShouldWork.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/RTLModePaddingShouldWork.png new file mode 100644 index 000000000000..d33119240099 Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/RTLModePaddingShouldWork.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/RightToLeftFlowDirectionShouldWork.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/RightToLeftFlowDirectionShouldWork.png index 8118ea02e5ec..29909fd34686 100644 Binary files a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/RightToLeftFlowDirectionShouldWork.png and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/RightToLeftFlowDirectionShouldWork.png differ diff --git a/src/Core/src/Platform/Android/TextViewExtensions.cs b/src/Core/src/Platform/Android/TextViewExtensions.cs index fd3fe5cbde17..ba6194d0e19f 100644 --- a/src/Core/src/Platform/Android/TextViewExtensions.cs +++ b/src/Core/src/Platform/Android/TextViewExtensions.cs @@ -87,7 +87,7 @@ public static void UpdateVerticalTextAlignment(this TextView textView, ITextAlig public static void UpdatePadding(this TextView textView, ILabel label) { - textView.SetPadding( + textView.SetPaddingRelative( (int)textView.ToPixels(label.Padding.Left), (int)textView.ToPixels(label.Padding.Top), (int)textView.ToPixels(label.Padding.Right), diff --git a/src/Core/src/Platform/iOS/MauiLabel.cs b/src/Core/src/Platform/iOS/MauiLabel.cs index 34784fe763cc..f1237e42e9bb 100644 --- a/src/Core/src/Platform/iOS/MauiLabel.cs +++ b/src/Core/src/Platform/iOS/MauiLabel.cs @@ -35,7 +35,20 @@ public MauiLabel() public override void DrawText(RectangleF rect) { - rect = TextInsets.InsetRect(rect); + var insets = TextInsets; + + // Respect RTL (flip left/right insets) + if (EffectiveUserInterfaceLayoutDirection == UIUserInterfaceLayoutDirection.RightToLeft) + { + insets = new UIEdgeInsets( + insets.Top, + insets.Right, + insets.Bottom, + insets.Left); + } + + rect = insets.InsetRect(rect); + if (_verticalAlignment != UIControlContentVerticalAlignment.Center && _verticalAlignment != UIControlContentVerticalAlignment.Fill)