mirror of
https://github.com/bitwarden/android.git
synced 2024-12-26 19:08:32 +03:00
PM-3349 PM-3350 Workaround to fix issues with text getting cropped/truncated when a Label has both Multiline and LinebreakMode set
This commit is contained in:
parent
80c424ed03
commit
0a628cc8a8
5 changed files with 51 additions and 2 deletions
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
src/Core/Controls/TruncatedMultilineCustomLabel.cs
Normal file
12
src/Core/Controls/TruncatedMultilineCustomLabel.cs
Normal file
|
@ -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
|
||||
{
|
||||
}
|
||||
}
|
|
@ -61,7 +61,7 @@
|
|||
<StackLayout
|
||||
Padding="16,12"
|
||||
Orientation="Horizontal">
|
||||
<controls:CustomLabel
|
||||
<controls:TruncatedMultilineCustomLabel
|
||||
Text="{Binding AppInfo}"
|
||||
MaxLines="10"
|
||||
StyleClass="box-footer-label"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
RowDefinitions="Auto,*"
|
||||
ColumnDefinitions="*,Auto"
|
||||
ColumnSpacing="10">
|
||||
<controls:CustomLabel
|
||||
<controls:TruncatedMultilineCustomLabel
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
MaxLines="2"
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using Bit.App.Controls;
|
||||
using Microsoft.Maui.Handlers;
|
||||
using UIKit;
|
||||
|
||||
namespace Bit.iOS.Core.Handlers
|
||||
{
|
||||
|
@ -13,6 +15,23 @@ namespace Bit.iOS.Core.Handlers
|
|||
handler.PlatformView.AccessibilityIdentifier = customLabel.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 Android
|
||||
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.LineBreakMode == UILineBreakMode.TailTruncation
|
||||
&& controlsLabel.MaxLines != -1)
|
||||
{
|
||||
textView.Lines = controlsLabel.MaxLines;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue