1
0
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:
Kyle Spearrin
2016-06-28 23:44:47 -04:00
parent 734d2632dc
commit 2e9410846e
12 changed files with 206 additions and 30 deletions

View 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);
}
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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" />