Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
381bb24
Fixed - 10987 - Editor HorizontalTextAlignment Does not Works.
NirmalKumarYuvaraj Oct 8, 2024
19dbacd
Added test case images
NirmalKumarYuvaraj Oct 8, 2024
2b994a8
Modified code changes
NirmalKumarYuvaraj Oct 8, 2024
3a07211
Replaced test case images
NirmalKumarYuvaraj Oct 8, 2024
59af2a7
Modified test images
NirmalKumarYuvaraj Oct 8, 2024
93a95ac
Added Windows test case image
NirmalKumarYuvaraj Oct 9, 2024
c60834b
Modified code changes
NirmalKumarYuvaraj Oct 10, 2024
3920326
Added android test images
NirmalKumarYuvaraj Oct 11, 2024
dd111e7
Fixed - 10987 - Editor HorizontalTextAlignment Does not Works.
NirmalKumarYuvaraj Oct 8, 2024
5f8c204
Added test case images
NirmalKumarYuvaraj Oct 8, 2024
6820218
Modified code changes
NirmalKumarYuvaraj Oct 8, 2024
f4d6c4f
Replaced test case images
NirmalKumarYuvaraj Oct 8, 2024
ebbebf6
Modified test images
NirmalKumarYuvaraj Oct 8, 2024
b6c8481
Added RTL Editor testcases and images
NirmalKumarYuvaraj Oct 25, 2024
5462662
Modified test script file and added images
NirmalKumarYuvaraj Oct 28, 2024
dd53e39
Added pending test images
NirmalKumarYuvaraj Oct 29, 2024
e939062
Modified code changes
NirmalKumarYuvaraj Nov 25, 2024
067f16a
Updated code changes
NirmalKumarYuvaraj Jan 9, 2025
a4eddf2
Added Mac snapshots
NirmalKumarYuvaraj Jan 15, 2025
6f733ff
Added mac and android snapshots
NirmalKumarYuvaraj Feb 14, 2025
c67d7b1
Updated code changes
NirmalKumarYuvaraj Feb 28, 2025
43eb493
Modified test cases
NirmalKumarYuvaraj Mar 11, 2025
86307f3
modified test case
NirmalKumarYuvaraj May 21, 2025
c3cdcc6
Fixed test case failures
NirmalKumarYuvaraj Jul 17, 2025
ee203fd
updated unshipped files
NirmalKumarYuvaraj Jul 28, 2025
5f15c94
Added failure snaps
NirmalKumarYuvaraj Sep 11, 2025
ac297ed
addressed failures
NirmalKumarYuvaraj Nov 3, 2025
a3f2f52
replaced android images
NirmalKumarYuvaraj Mar 23, 2026
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
46 changes: 46 additions & 0 deletions src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,52 @@ await CreateHandlerAndAddToWindow(contentPage, async () =>
Assert.Equal(expectedFontFamily, placeholderLabel?.Font?.FamilyName);
});
}

[Fact]
public async Task PlaceholderHorizontalTextAlignment()
{
EnsureHandlerCreated(builder =>
{
builder.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler(typeof(Editor), typeof(EditorHandler));
});
});

var horizontalEndAlignment = TextAlignment.End;
var horizontalCenterAlignment = TextAlignment.Center;
var horizontalStartAlignment = TextAlignment.Start;

var editor = new Editor
{
Placeholder = "This is a placeholder"
};

ContentPage contentPage = new ContentPage()
{
Content = new VerticalStackLayout()
{
editor
}
};

await CreateHandlerAndAddToWindow(contentPage, async () =>
{
await AssertEventually(() => editor.IsVisible);
var handler = CreateHandler<EditorHandler>(editor);
var platformControl = GetPlatformControl(handler);

var placeholderLabel = handler.PlatformView.Subviews.OfType<UIKit.UILabel>().FirstOrDefault();

editor.HorizontalTextAlignment = horizontalCenterAlignment;
Assert.Equal(UIKit.UITextAlignment.Center, placeholderLabel?.TextAlignment);
editor.HorizontalTextAlignment = horizontalEndAlignment;
Assert.Equal(UIKit.UITextAlignment.Right, placeholderLabel?.TextAlignment);
editor.HorizontalTextAlignment = horizontalStartAlignment;
Assert.Equal(UIKit.UITextAlignment.Left, placeholderLabel?.TextAlignment);

});
}
}

//src/Compatibility/Core/tests/iOS/FlowDirectionTests.cs
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue10987.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 10987, "Editor HorizontalTextAlignment Does not Works.", PlatformAffected.All)]
public class Issue10987 : TestContentPage
{
Editor lTReditor, rTLeditor;
Button updateAlignmentButton, resetAlignmentButton;
protected override void Init()
{

updateAlignmentButton = CreateButton("UpdateAlignmentButton", "Update alignment");
resetAlignmentButton = CreateButton("ResetAlignmentButton", "Reset alignment");

updateAlignmentButton.Clicked += OnUpdateAlignmentButtonClicked;
resetAlignmentButton.Clicked += OnResetAlignmentButtonClicked;

lTReditor = CreateEditor("LTREditor", "placeholder text", FlowDirection.LeftToRight);
rTLeditor = CreateEditor("RTLEditor", "placeholder text", FlowDirection.RightToLeft);

Content = new VerticalStackLayout
{
Spacing = 25,
VerticalOptions = LayoutOptions.Center,
Children =
{
updateAlignmentButton,
resetAlignmentButton,
lTReditor,
rTLeditor
}
};
}

Button CreateButton(string automationId, string text)
{
Button button = new Button();
button.AutomationId = automationId;
button.Text = text;
return button;
}

Editor CreateEditor(string automationId, string placeholderText, FlowDirection flowDirection)
{
Editor editor = new Editor();
editor.AutomationId = automationId;
editor.BackgroundColor = Colors.LightBlue;
editor.Placeholder = placeholderText;
editor.HeightRequest = 250;
editor.WidthRequest = 220;
editor.FlowDirection = flowDirection;
return editor;
}

private void OnResetAlignmentButtonClicked(object sender, EventArgs e)
{
lTReditor.VerticalTextAlignment = TextAlignment.Start;
lTReditor.HorizontalTextAlignment = TextAlignment.Start;
lTReditor.Unfocus();

rTLeditor.VerticalTextAlignment = TextAlignment.Start;
rTLeditor.HorizontalTextAlignment = TextAlignment.Start;
rTLeditor.Unfocus();
}

private void OnUpdateAlignmentButtonClicked(object sender, EventArgs e)
{
lTReditor.VerticalTextAlignment = TextAlignment.End;
lTReditor.HorizontalTextAlignment = TextAlignment.End;

rTLeditor.VerticalTextAlignment = TextAlignment.End;
rTLeditor.HorizontalTextAlignment = TextAlignment.End;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;
namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue10987 : _IssuesUITest
{
const string LTREditor = "LTREditor";
const string RTLEditor = "RTLEditor";
public Issue10987(TestDevice device) : base(device) { }

public override string Issue => "Editor HorizontalTextAlignment Does not Works.";

[Test]
[Category(UITestCategories.Editor)]
public void EditorPlaceholderRuntimeTextAlignmentChanged()
{
App.WaitForElement(RTLEditor);
App.Tap("UpdateAlignmentButton");
VerifyScreenshot();
}

[Test]
[Category(UITestCategories.Editor)]
public void EditorRuntimeTextAlignmentChanged()
{
//To make sure editor is focused in mac platform
App.Tap(LTREditor);
App.EnterText(LTREditor, "Editor Text");
App.WaitForElement(RTLEditor);
App.EnterText(RTLEditor, "RTL Editor");
#if IOS
Copy link

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Platform-specific preprocessor directives in test code should be avoided when possible. Consider using runtime platform detection or abstracting this behavior.

Copilot uses AI. Check for mistakes.
var app = App as AppiumApp;
KeyboardScrolling.HideKeyboard(app!, app!.Driver, true);
#endif
App.Tap("ResetAlignmentButton");
VerifyScreenshot();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/Editor/EditorHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ protected override MauiAppCompatEditText CreatePlatformView()
var editText = new MauiAppCompatEditText(Context)
{
ImeOptions = ImeAction.Done,
Gravity = GravityFlags.Top,
TextAlignment = global::Android.Views.TextAlignment.ViewStart,
Gravity = GravityFlags.Top,
};

editText.SetSingleLine(false);
Expand Down
9 changes: 3 additions & 6 deletions src/Core/src/Platform/Android/TextAlignmentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ public static class TextAlignmentExtensions

internal static void UpdateHorizontalAlignment(this EditText view, TextAlignment alignment, AGravityFlags orMask = AGravityFlags.NoGravity)
{
if (!Rtl.IsSupported)
{
view.Gravity = (view.Gravity & ~HorizontalGravityMask) | alignment.ToHorizontalGravityFlags() | orMask;
}
else
view.TextAlignment = alignment.ToTextAlignment();
// The text alignment does not work at runtime, so we also need to update the gravity.
view.TextAlignment = alignment.ToTextAlignment();
view.Gravity = (view.Gravity & ~HorizontalGravityMask) | alignment.ToHorizontalGravityFlags() | orMask;
}

public static void UpdateVerticalAlignment(this EditText view, TextAlignment alignment, AGravityFlags orMask = AGravityFlags.NoGravity)
Expand Down
37 changes: 35 additions & 2 deletions src/Core/src/Platform/iOS/MauiTextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class MauiTextView : UITextView, IUIViewLifeCycleEvents
[UnconditionalSuppressMessage("Memory", "MEM0002", Justification = "Proven safe in test: MemoryTests.HandlerDoesNotLeak")]
readonly MauiLabel _placeholderLabel;
nfloat? _defaultPlaceholderSize;
TextAlignment _verticalTextAlignment;

public MauiTextView()
{
Expand All @@ -34,6 +35,19 @@ public override void WillMoveToWindow(UIWindow? window)
base.WillMoveToWindow(window);
}

public override UITextAlignment TextAlignment
{
get => base.TextAlignment;
set
{
if (base.TextAlignment != value)
{
base.TextAlignment = value;
UpdateHorizontalTextAlignment(value);
}
}
}

// Native Changed doesn't fire when the Text Property is set in code
// We use this event as a way to fire changes whenever the Text changes
// via code or user interaction.
Expand Down Expand Up @@ -66,7 +80,18 @@ public UIColor? PlaceholderTextColor
set => _placeholderLabel.TextColor = value;
}

public TextAlignment VerticalTextAlignment { get; set; }
public TextAlignment VerticalTextAlignment
{
get => _verticalTextAlignment;
set
{
if (_verticalTextAlignment != value)
{
_verticalTextAlignment = value;
ShouldCenterVertically();
}
}
}

public override string? Text
{
Expand Down Expand Up @@ -136,6 +161,14 @@ MauiLabel InitPlaceholderLabel()
return placeholderLabel;
}

void UpdateHorizontalTextAlignment(UITextAlignment textAlignment)
{
if (_placeholderLabel is null)
return;

_placeholderLabel.TextAlignment = textAlignment;
}

void UpdatePlaceholderLabelFrame()
{
if (Bounds != CGRect.Empty && _placeholderLabel is not null)
Expand Down Expand Up @@ -170,7 +203,7 @@ void ShouldCenterVertically()
{
Maui.TextAlignment.Center => new CGPoint(0, -Math.Max(1, availableSpace / 2)),
Maui.TextAlignment.End => new CGPoint(0, -Math.Max(1, availableSpace)),
_ => ContentOffset,
_ => default,
};

// Scroll the content to the cursor position if it is hidden by the keyboard
Expand Down
5 changes: 5 additions & 0 deletions src/Core/src/Platform/iOS/TextViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ public static void UpdateHorizontalTextAlignment(this UITextView textView, IEdit
textView.TextAlignment = editor.HorizontalTextAlignment.ToPlatformHorizontal(textView.EffectiveUserInterfaceLayoutDirection);
}

internal static void UpdateHorizontalTextAlignment(this MauiTextView textView, IEditor editor)
{
textView.TextAlignment = editor.HorizontalTextAlignment.ToPlatformHorizontal(textView.EffectiveUserInterfaceLayoutDirection);
}

public static void UpdateVerticalTextAlignment(this MauiTextView textView, IEditor editor)
{
textView.VerticalTextAlignment = editor.VerticalTextAlignment;
Expand Down
2 changes: 2 additions & 0 deletions src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#nullable enable
override Microsoft.Maui.Platform.MauiView.DidUpdateFocus(UIKit.UIFocusUpdateContext! context, UIKit.UIFocusAnimationCoordinator! coordinator) -> void
override Microsoft.Maui.Platform.MauiTextView.TextAlignment.get -> UIKit.UITextAlignment
override Microsoft.Maui.Platform.MauiTextView.TextAlignment.set -> void
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#nullable enable
override Microsoft.Maui.Platform.MauiView.DidUpdateFocus(UIKit.UIFocusUpdateContext! context, UIKit.UIFocusAnimationCoordinator! coordinator) -> void
override Microsoft.Maui.Platform.MauiTextView.TextAlignment.get -> UIKit.UITextAlignment
override Microsoft.Maui.Platform.MauiTextView.TextAlignment.set -> void
Loading