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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue30192.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 30192, "TimePicker FlowDirection Not Working on All Platforms", PlatformAffected.All)]
public class Issue30192 : ContentPage
{
public Issue30192()
{
TimePicker ltrTimePicker = new TimePicker
{
Time = new TimeSpan(2, 0, 0),
Format = "hh:mm tt",
FlowDirection = FlowDirection.LeftToRight,
};

TimePicker rtlTimePicker = new TimePicker
{
Time = new TimeSpan(2, 0, 0),
Format = "hh:mm tt",
FlowDirection = FlowDirection.RightToLeft,
};

Button button = new Button
{
Text = "Toggle FlowDirection",
AutomationId = "ToggleFlowDirectionButton"
};
button.Clicked += (sender, e) =>
{
ltrTimePicker.FlowDirection = FlowDirection.RightToLeft;
rtlTimePicker.FlowDirection = FlowDirection.LeftToRight;
};

Content = new VerticalStackLayout
{
Children =
{
ltrTimePicker,
rtlTimePicker,
button
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#if TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_WINDOWS // https://github.com/dotnet/maui/issues/30322
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue30192 : _IssuesUITest
{
public Issue30192(TestDevice testDevice) : base(testDevice)
{
}
public override string Issue => "TimePicker FlowDirection Not Working on All Platforms";

[Test]
[Category(UITestCategories.TimePicker)]
public void TimePickerFlowDirectionTest()
{
App.WaitForElement("ToggleFlowDirectionButton");
App.Tap("ToggleFlowDirectionButton");
VerifyScreenshot();
}
}
#endif
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.
16 changes: 16 additions & 0 deletions src/Core/src/Handlers/TimePicker/TimePickerHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ public static void MapFont(ITimePickerHandler handler, ITimePicker timePicker)
handler.PlatformView?.UpdateFont(timePicker, fontManager);
}

// Make it public in .NET 11.
internal static void MapFlowDirection(ITimePickerHandler handler, ITimePicker timePicker)
{
if (handler.PlatformView is not null)
{
handler.PlatformView.UpdateFlowDirection(timePicker);

// For 12-hour format, also apply text alignment to handle AM/PM positioning
// For 24-hour format, UpdateFlowDirection alone is sufficient
if (handler is TimePickerHandler timePickerHandler && !timePickerHandler.Use24HourView)
{
handler.PlatformView.UpdateTextAlignment(timePicker);
}
}
}

public static void MapTextColor(ITimePickerHandler handler, ITimePicker timePicker)
{
handler.PlatformView?.UpdateTextColor(timePicker);
Expand Down
3 changes: 2 additions & 1 deletion src/Core/src/Handlers/TimePicker/TimePickerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public partial class TimePickerHandler : ITimePickerHandler
{
#if ANDROID || WINDOWS
[nameof(ITimePicker.Background)] = MapBackground,
#elif IOS
#endif
#if IOS || ANDROID
[nameof(ITimePicker.FlowDirection)] = MapFlowDirection,
#endif
[nameof(ITimePicker.CharacterSpacing)] = MapCharacterSpacing,
Expand Down
10 changes: 10 additions & 0 deletions src/Core/src/Handlers/TimePicker/TimePickerHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ public static void MapFlowDirection(TimePickerHandler handler, ITimePicker timeP
handler.PlatformView?.UpdateTextAlignment(timePicker);
}

// Make it public in .NET 11 and remove the concrete TimePickerHandler overload.
internal static void MapFlowDirection(ITimePickerHandler handler, ITimePicker timePicker)
{
if (handler.PlatformView is not null)
{
handler.PlatformView.UpdateFlowDirection(timePicker);
handler.PlatformView.UpdateTextAlignment(timePicker);
}
}

internal static void MapIsOpen(ITimePickerHandler handler, ITimePicker timePicker)
{
handler.PlatformView?.UpdateIsOpen(timePicker);
Expand Down
11 changes: 10 additions & 1 deletion src/Core/src/Platform/Android/TimePickerExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Android.Content.Res;
using AndroidX.AppCompat.Widget;
using ATextAlignment = Android.Views.TextAlignment;

namespace Microsoft.Maui.Platform;

Expand Down Expand Up @@ -59,4 +60,12 @@ static void UpdateTextColorImpl(AppCompatEditText platformTimePicker, ITimePicke
}
}
}
}

// Make it public in .NET 11.
internal static void UpdateTextAlignment(this MauiTimePicker mauiTimePicker, ITimePicker timePicker)
{
mauiTimePicker.TextAlignment = timePicker.FlowDirection == FlowDirection.RightToLeft
? ATextAlignment.TextEnd
: ATextAlignment.TextStart;
}
}
4 changes: 3 additions & 1 deletion src/Core/src/Platform/iOS/TimePickerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ public static void UpdateTime(this MauiTimePicker mauiTimePicker, ITimePicker ti

public static void UpdateTextAlignment(this MauiTimePicker textField, ITimePicker timePicker)
{
// TODO: Update TextAlignment based on the EffectiveFlowDirection property.
UISemanticContentAttribute updateValue = textField.SemanticContentAttribute;

textField.TextAlignment = (updateValue == UISemanticContentAttribute.ForceRightToLeft) ? UITextAlignment.Right : UITextAlignment.Left;
}

internal static void UpdateIsOpen(this UIDatePicker picker, ITimePicker timePicker)
Expand Down
Loading