mirror of
https://github.com/bitwarden/mobile
synced 2026-01-06 18:43:43 +00:00
Optimizations for dynamic text sizes.
This commit is contained in:
40
src/iOS/Controls/CustomButtonRenderer.cs
Normal file
40
src/iOS/Controls/CustomButtonRenderer.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using Bit.iOS.Controls;
|
||||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.iOS;
|
||||
|
||||
[assembly: ExportRenderer(typeof(Button), typeof(CustomButtonRenderer))]
|
||||
namespace Bit.iOS.Controls
|
||||
{
|
||||
public class CustomButtonRenderer : ButtonRenderer
|
||||
{
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
|
||||
{
|
||||
base.OnElementChanged(e);
|
||||
|
||||
var view = e.NewElement as Button;
|
||||
if(Control != null && view != null)
|
||||
{
|
||||
var descriptor = UIFontDescriptor.PreferredBody;
|
||||
var pointSize = descriptor.PointSize;
|
||||
|
||||
var size = view.FontSize;
|
||||
if(size == Device.GetNamedSize(NamedSize.Large, typeof(Button)))
|
||||
{
|
||||
pointSize *= 1.4f;
|
||||
}
|
||||
else if(size == Device.GetNamedSize(NamedSize.Small, typeof(Button)))
|
||||
{
|
||||
pointSize *= .8f;
|
||||
}
|
||||
else if(size == Device.GetNamedSize(NamedSize.Micro, typeof(Button)))
|
||||
{
|
||||
pointSize *= .6f;
|
||||
}
|
||||
|
||||
Control.Font = UIFont.FromDescriptor(descriptor, pointSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ namespace Bit.iOS.Controls
|
||||
var size = view.FontSize;
|
||||
if(size == Device.GetNamedSize(NamedSize.Large, typeof(Label)))
|
||||
{
|
||||
pointSize *= 1.7f;
|
||||
pointSize *= 1.4f;
|
||||
}
|
||||
else if(size == Device.GetNamedSize(NamedSize.Small, typeof(Label)))
|
||||
{
|
||||
@@ -33,7 +33,7 @@ namespace Bit.iOS.Controls
|
||||
pointSize *= .6f;
|
||||
}
|
||||
|
||||
UIFont.FromDescriptor(descriptor, pointSize);
|
||||
Control.Font = UIFont.FromDescriptor(descriptor, pointSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ namespace Bit.iOS.Controls
|
||||
var view = e.NewElement as ExtendedEntry;
|
||||
if(view != null)
|
||||
{
|
||||
UIFont.FromDescriptor(UIFontDescriptor.PreferredBody, 1.0f);
|
||||
var descriptor = UIFontDescriptor.PreferredBody;
|
||||
Control.Font = UIFont.FromDescriptor( descriptor, descriptor.PointSize );
|
||||
|
||||
SetBorder(view);
|
||||
SetMaxLength(view);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Bit.App.Controls;
|
||||
using Bit.iOS.Controls;
|
||||
using CoreGraphics;
|
||||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.iOS;
|
||||
@@ -17,6 +18,31 @@ namespace Bit.iOS.Controls
|
||||
if(cell != null)
|
||||
{
|
||||
cell.BackgroundColor = extendedCell.BackgroundColor.ToUIColor();
|
||||
if(extendedCell.ShowDisclousure)
|
||||
{
|
||||
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
|
||||
if(!string.IsNullOrEmpty(extendedCell.DisclousureImage))
|
||||
{
|
||||
var detailDisclosureButton = UIButton.FromType(UIButtonType.Custom);
|
||||
detailDisclosureButton.SetImage(UIImage.FromBundle(extendedCell.DisclousureImage), UIControlState.Normal);
|
||||
|
||||
try
|
||||
{
|
||||
detailDisclosureButton.SetImage(UIImage.FromBundle(extendedCell.DisclousureImage + "_selected"), UIControlState.Selected);
|
||||
}
|
||||
catch
|
||||
{
|
||||
detailDisclosureButton.SetImage(UIImage.FromBundle(extendedCell.DisclousureImage), UIControlState.Selected);
|
||||
}
|
||||
|
||||
detailDisclosureButton.Frame = new CGRect(0f, 0f, 50f, 40f);
|
||||
detailDisclosureButton.TouchUpInside += (sender, e) =>
|
||||
{
|
||||
extendedCell.OnDisclousureTapped();
|
||||
};
|
||||
cell.AccessoryView = detailDisclosureButton;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cell;
|
||||
|
||||
@@ -101,6 +101,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controls\ContentPageRenderer.cs" />
|
||||
<Compile Include="Controls\CustomButtonRenderer.cs" />
|
||||
<Compile Include="Controls\CustomLabelRenderer.cs" />
|
||||
<Compile Include="Controls\ExtendedSwitchCellRenderer.cs" />
|
||||
<Compile Include="Controls\ListViewRenderer.cs" />
|
||||
|
||||
Reference in New Issue
Block a user