1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-09-18 02:31:15 +02:00

PM-3350 Removed ButtonHandlerMappings and some other code related with fonts as MAUI is taking care of Accessibility and no custom code should be needed

Migrated SelectableLabelRenderer to Handler
Cleaned LabelHandlerMappings and added logic to migrate the CustomLabelRenderer
This commit is contained in:
Dinis Vieira 2023-10-18 01:21:19 +01:00
parent 455c3a257c
commit 14b2960f30
No known key found for this signature in database
GPG Key ID: 9389160FF6C295F3
5 changed files with 74 additions and 100 deletions

View File

@ -1,21 +0,0 @@
using System;
using Bit.iOS.Core.Utilities;
namespace Bit.iOS.Core.Handlers
{
public class ButtonHandlerMappings
{
public static void Setup()
{
// TODO: [Maui-Migration] Check if this is needed given that on MAUI FontAutoScalingEnabled is true by default.
//Microsoft.Maui.Handlers.ButtonHandler.Mapper.AppendToMapping("CustomButtonHandler", (handler, button) =>
//{
// var pointSize = iOSHelpers.GetAccessibleFont<Button>(button.FontSize);
// if (pointSize != null)
// {
// handler.PlatformView.Font = UIFont.FromDescriptor(Element.Font.ToUIFont().FontDescriptor, pointSize.Value);
// }
//});
}
}
}

View File

@ -14,8 +14,6 @@ namespace Bit.iOS.Core.Handlers
handler.PlatformView.ClearButtonMode = UITextFieldViewMode.WhileEditing;
UpdateTintColor(handler, editor);
iOSHelpers.SetBottomBorder(handler.PlatformView);
// TODO: [Maui-Migration] Check if needed given that MAUI should be automatically change the font size based on OS accessbiility
//UpdateFontSize();
if (!ThemeHelpers.LightTheme)
{

View File

@ -1,83 +1,18 @@
using Bit.App.Controls;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using UIKit;
namespace Bit.iOS.Core.Handlers
{
public class LabelHandlerMappings
{
// TODO: [Maui-Migration] See if the SelectableLabel is needed.
//public static void Setup()
//{
// LabelHandler.Mapper.AppendToMapping(nameof(ILabel.TextColor), (handler, label) =>
// {
// if (label is SelectableLabel selectableLabel)
// {
// handler.PlatformView.Selectable = true;
// handler.PlatformView.Editable = false;
// handler.PlatformView.ScrollEnabled = false;
// handler.PlatformView.TextContainerInset = UIEdgeInsets.Zero;
// handler.PlatformView.TextContainer.LineFragmentPadding = 0;
// handler.PlatformView.BackgroundColor = UIColor.Clear;
// handler.PlatformView.Text = selectableLabel.Text;
// handler.PlatformView.TextColor = selectableLabel.TextColor.ToPlatform();
// }
// });
//}
// TODO: [Maui-Migration] Check if needed to migrate given that MAUI should be automatically change the font size based on OS accessbiility
//protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
//{
// base.OnElementChanged(e);
// if (Control != null && e.NewElement is Label)
// {
// UpdateFont();
// }
//}
//protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
//{
// var label = sender as CustomLabel;
// switch (e.PropertyName)
// {
// case nameof(CustomLabel.AutomationId):
// Control.AccessibilityIdentifier = label.AutomationId;
// break;
// }
// base.OnElementPropertyChanged(sender, e);
// if (e.PropertyName == Label.FontProperty.PropertyName ||
// e.PropertyName == Label.TextProperty.PropertyName ||
// e.PropertyName == Label.FormattedTextProperty.PropertyName)
// {
// UpdateFont();
// }
//}
//private void UpdateFont()
//{
// if (Element is null || Control is null)
// return;
// var pointSize = iOSHelpers.GetAccessibleFont<Label>(Element.FontSize);
// if (pointSize != null)
// {
// Control.Font = UIFont.FromDescriptor(Element.ToUIFont().FontDescriptor, pointSize.Value);
// }
// // TODO: For now, I'm only doing this for IconLabel with setup just in case I break the whole app labels.
// // We need to revisit this when we address Accessibility Large Font issues across the app
// // to check if we can left it more generic like
// // else if (Element.FontFamily != null)
// else if (Element is IconLabel iconLabel && iconLabel.ShouldUpdateFontSizeDynamicallyForAccesibility)
// {
// var customFont = Element.ToUIFont();
// Control.Font = new UIFontMetrics(UIFontTextStyle.Body.GetConstant()).GetScaledFont(customFont);
// }
//}
public static void Setup()
{
Microsoft.Maui.Handlers.LabelHandler.Mapper.AppendToMapping(nameof(ILabel.AutomationId), (handler, label) =>
{
if (label is CustomLabel customLabel)
{
handler.PlatformView.AccessibilityIdentifier = customLabel.AutomationId;
}
});
}
}
}

View File

@ -0,0 +1,62 @@
using Bit.App.Controls;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using UIKit;
namespace Bit.iOS.Core.Handlers
{
public partial class SelectableLabelHandler : ViewHandler<SelectableLabel, UITextView>
{
public static PropertyMapper<SelectableLabel, SelectableLabelHandler> PropertyMapper = new PropertyMapper<SelectableLabel, SelectableLabelHandler>(ViewHandler.ViewMapper)
{
[nameof(SelectableLabel.Text)] = MapText,
[nameof(SelectableLabel.TextColor)] = MapTextColor,
[nameof(SelectableLabel.FontAttributes)] = MapFontAttributes,
};
public SelectableLabelHandler() : base(PropertyMapper)
{
}
protected override UITextView CreatePlatformView()
{
var uiTextView = new UITextView();
uiTextView.Selectable = true;
uiTextView.Editable = false;
uiTextView.ScrollEnabled = false;
uiTextView.TextContainerInset = UIEdgeInsets.Zero;
uiTextView.TextContainer.LineFragmentPadding = 0;
uiTextView.BackgroundColor = UIColor.Clear;
return uiTextView;
}
private static void MapText(SelectableLabelHandler handler, SelectableLabel label)
{
handler.PlatformView.Text = label.Text;
}
private static void MapTextColor(SelectableLabelHandler handler, SelectableLabel label)
{
handler.PlatformView.TextColor = label.TextColor.ToPlatform();
}
private static void MapFontAttributes(SelectableLabelHandler handler, SelectableLabel label)
{
switch (label.FontAttributes)
{
case FontAttributes.None:
handler.PlatformView.Font = UIFont.SystemFontOfSize(new nfloat(label.FontSize));
break;
case FontAttributes.Bold:
handler.PlatformView.Font = UIFont.BoldSystemFontOfSize(new nfloat(label.FontSize));
break;
case FontAttributes.Italic:
handler.PlatformView.Font = UIFont.ItalicSystemFontOfSize(new nfloat(label.FontSize));
break;
default:
handler.PlatformView.Font = UIFont.BoldSystemFontOfSize(new nfloat(label.FontSize));
break;
}
}
}
}

View File

@ -49,11 +49,11 @@ namespace Bit.iOS.Core.Utilities
handlers.AddHandler(typeof(NavigationPage), typeof(Handlers.CustomNavigationHandler));
handlers.AddHandler(typeof(ViewCell), typeof(Handlers.CustomViewCellHandler));
handlers.AddHandler(typeof(ContentPage), typeof(Handlers.CustomContentPageHandler));
Handlers.ButtonHandlerMappings.Setup();
handlers.AddHandler(typeof(SelectableLabel), typeof(Handlers.SelectableLabelHandler));
Handlers.DatePickerHandlerMappings.Setup();
Handlers.EditorHandlerMappings.Setup();
Handlers.EntryHandlerMappings.Setup();
//Handlers.LabelHandlerMappings.Setup();
Handlers.LabelHandlerMappings.Setup();
Handlers.PickerHandlerMappings.Setup();
Handlers.SearchBarHandlerMappings.Setup();
Handlers.StepperHandlerMappings.Setup();