From 0a628cc8a8416eb0708caf404979a3389c6accb0 Mon Sep 17 00:00:00 2001 From: Dinis Vieira Date: Sun, 26 Nov 2023 14:46:30 +0000 Subject: [PATCH] PM-3349 PM-3350 Workaround to fix issues with text getting cropped/truncated when a Label has both Multiline and LinebreakMode set --- .../Android/Handlers/LabelHandlerMappings.cs | 18 ++++++++++++++++++ .../Controls/TruncatedMultilineCustomLabel.cs | 12 ++++++++++++ .../Pages/Settings/AboutSettingsPage.xaml | 2 +- .../Resources/Styles/ControlTemplates.xaml | 2 +- src/iOS.Core/Handlers/LabelHandlerMappings.cs | 19 +++++++++++++++++++ 5 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/Core/Controls/TruncatedMultilineCustomLabel.cs diff --git a/src/App/Platforms/Android/Handlers/LabelHandlerMappings.cs b/src/App/Platforms/Android/Handlers/LabelHandlerMappings.cs index 22a346d27..9d8fcd569 100644 --- a/src/App/Platforms/Android/Handlers/LabelHandlerMappings.cs +++ b/src/App/Platforms/Android/Handlers/LabelHandlerMappings.cs @@ -1,5 +1,6 @@ using Android.OS; using Bit.App.Controls; +using Microsoft.Maui.Handlers; namespace Bit.App.Handlers { @@ -26,6 +27,23 @@ namespace Bit.App.Handlers { handler.PlatformView.ContentDescription = label.AutomationId; }); + + // WORKAROUND: There is an issue causing Multiline Labels that also have a LineBreakMode to not display text properly. (it truncates text on first line even with space available) + // MAUI Github Issue: https://github.com/dotnet/maui/issues/14125 and https://github.com/dotnet/maui/pull/14918 + // When this gets fixed by MAUI these two Mapping below can be deleted, same for the UpdateMaxLines, TruncatedMultilineCustomLabel class and the equivalent Mappings on iOS + Microsoft.Maui.Handlers.LabelHandler.Mapper.AppendToMapping(nameof(Label.LineBreakMode), UpdateMaxLines); + Microsoft.Maui.Handlers.LabelHandler.Mapper.AppendToMapping(nameof(Label.MaxLines), UpdateMaxLines); + } + + private static void UpdateMaxLines(ILabelHandler handler, ILabel label) + { + var textView = handler.PlatformView; + if(label is TruncatedMultilineCustomLabel controlsLabel + && textView.Ellipsize == Android.Text.TextUtils.TruncateAt.End + && controlsLabel.MaxLines != -1) + { + textView.SetMaxLines( controlsLabel.MaxLines ); + } } } } diff --git a/src/Core/Controls/TruncatedMultilineCustomLabel.cs b/src/Core/Controls/TruncatedMultilineCustomLabel.cs new file mode 100644 index 000000000..e634ca363 --- /dev/null +++ b/src/Core/Controls/TruncatedMultilineCustomLabel.cs @@ -0,0 +1,12 @@ +using Bit.App.Controls; + +namespace Bit.App.Controls +{ + // WORKAROUND: There is an issue causing Multiline Labels that also have a LineBreakMode to not display text properly. (it truncates text on first line even with space available) + // MAUI Github Issue: https://github.com/dotnet/maui/issues/14125 and https://github.com/dotnet/maui/pull/14918 + // This class is used to be able to only add the workaround to this specific Label avoiding potential issues on other "normal" Label + // When this gets fixed by MAUI we can remove this class and some of the Mapping in LabelHandlerMappings + public class TruncatedMultilineCustomLabel : CustomLabel + { + } +} diff --git a/src/Core/Pages/Settings/AboutSettingsPage.xaml b/src/Core/Pages/Settings/AboutSettingsPage.xaml index 9c141d092..125345f52 100644 --- a/src/Core/Pages/Settings/AboutSettingsPage.xaml +++ b/src/Core/Pages/Settings/AboutSettingsPage.xaml @@ -61,7 +61,7 @@ - -