From a9f9b25a1d5c94638a9022d7c54c04b227965827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Tue, 21 Mar 2023 14:44:03 +0100 Subject: [PATCH 1/3] Fix Android Picker RTL issues --- .../src/Handlers/Picker/PickerHandler.Android.cs | 2 ++ .../src/Platform/Android/FlowDirectionExtensions.cs | 13 +++++++++++++ src/Core/src/Platform/Android/PickerExtensions.cs | 13 ++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Core/src/Handlers/Picker/PickerHandler.Android.cs b/src/Core/src/Handlers/Picker/PickerHandler.Android.cs index 57a6d3f9839d..ffe3e01e0e9f 100644 --- a/src/Core/src/Handlers/Picker/PickerHandler.Android.cs +++ b/src/Core/src/Handlers/Picker/PickerHandler.Android.cs @@ -147,6 +147,8 @@ void OnClick(object? sender, EventArgs e) if (_dialog == null) return; + _dialog.UpdateFlowDirection(PlatformView); + _dialog.SetCanceledOnTouchOutside(true); _dialog.DismissEvent += (sender, args) => diff --git a/src/Core/src/Platform/Android/FlowDirectionExtensions.cs b/src/Core/src/Platform/Android/FlowDirectionExtensions.cs index 86bf26dc1b2b..e62571d8975e 100644 --- a/src/Core/src/Platform/Android/FlowDirectionExtensions.cs +++ b/src/Core/src/Platform/Android/FlowDirectionExtensions.cs @@ -19,5 +19,18 @@ internal static FlowDirection ToFlowDirection(this ALayoutDirection direction) return FlowDirection.MatchParent; } } + + internal static ATextDirection ToTextDirection(this ALayoutDirection direction) + { + switch (direction) + { + case ALayoutDirection.Ltr: + return ATextDirection.Ltr; + case ALayoutDirection.Rtl: + return ATextDirection.Rtl; + default: + return ATextDirection.Inherit; + } + } } } \ No newline at end of file diff --git a/src/Core/src/Platform/Android/PickerExtensions.cs b/src/Core/src/Platform/Android/PickerExtensions.cs index 63b59f8e9a65..44ac4ac9de3f 100644 --- a/src/Core/src/Platform/Android/PickerExtensions.cs +++ b/src/Core/src/Platform/Android/PickerExtensions.cs @@ -1,4 +1,5 @@ -using Android.Content.Res; +using Android.App; +using Android.Content.Res; namespace Microsoft.Maui.Platform { @@ -45,5 +46,15 @@ internal static void UpdatePicker(this MauiPicker platformPicker, IPicker picker else platformPicker.Text = picker.GetItem(picker.SelectedIndex); } + + internal static void UpdateFlowDirection(this AlertDialog alertDialog, MauiPicker platformPicker) + { + // Propagate the MauiPicker LayoutDirection to the AlertDialog + if (alertDialog.Window?.DecorView is not null) + alertDialog.Window.DecorView.LayoutDirection = platformPicker.LayoutDirection; + + if (alertDialog.ListView is not null) + alertDialog.ListView.TextDirection = platformPicker.LayoutDirection.ToTextDirection(); + } } } \ No newline at end of file From 9fece03f98ded967496e0e3668cc334cc6fa0c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Wed, 22 Mar 2023 10:18:04 +0100 Subject: [PATCH 2/3] More changes --- .../src/Platform/Android/PickerExtensions.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Core/src/Platform/Android/PickerExtensions.cs b/src/Core/src/Platform/Android/PickerExtensions.cs index 44ac4ac9de3f..4582f13607a4 100644 --- a/src/Core/src/Platform/Android/PickerExtensions.cs +++ b/src/Core/src/Platform/Android/PickerExtensions.cs @@ -49,12 +49,21 @@ internal static void UpdatePicker(this MauiPicker platformPicker, IPicker picker internal static void UpdateFlowDirection(this AlertDialog alertDialog, MauiPicker platformPicker) { + var platformLayoutDirection = platformPicker.LayoutDirection; + // Propagate the MauiPicker LayoutDirection to the AlertDialog - if (alertDialog.Window?.DecorView is not null) - alertDialog.Window.DecorView.LayoutDirection = platformPicker.LayoutDirection; + var dv = alertDialog.Window?.DecorView; + + if (dv is not null) + dv.LayoutDirection = platformLayoutDirection; + + var lv = alertDialog?.ListView; - if (alertDialog.ListView is not null) - alertDialog.ListView.TextDirection = platformPicker.LayoutDirection.ToTextDirection(); + if (lv is not null) + { + lv.LayoutDirection = platformLayoutDirection; + lv.TextDirection = platformLayoutDirection.ToTextDirection(); + } } } } \ No newline at end of file From bd539c8ce0db941547f5cb04cfe27e14b47b7871 Mon Sep 17 00:00:00 2001 From: GitHub Actions Autoformatter Date: Wed, 22 Mar 2023 09:20:35 +0000 Subject: [PATCH 3/3] Auto-format source code --- src/Core/src/Platform/Android/PickerExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/src/Platform/Android/PickerExtensions.cs b/src/Core/src/Platform/Android/PickerExtensions.cs index 4582f13607a4..71aaef380d1f 100644 --- a/src/Core/src/Platform/Android/PickerExtensions.cs +++ b/src/Core/src/Platform/Android/PickerExtensions.cs @@ -56,7 +56,7 @@ internal static void UpdateFlowDirection(this AlertDialog alertDialog, MauiPicke if (dv is not null) dv.LayoutDirection = platformLayoutDirection; - + var lv = alertDialog?.ListView; if (lv is not null)