mirror of
https://github.com/bitwarden/android.git
synced 2024-12-18 23:31:52 +03:00
Adjusted button and entry to handle font upadte on property changes
This commit is contained in:
parent
98335c6acb
commit
596a74b394
2 changed files with 67 additions and 21 deletions
|
@ -3,6 +3,7 @@ using Bit.iOS.Controls;
|
|||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.iOS;
|
||||
using System.ComponentModel;
|
||||
|
||||
[assembly: ExportRenderer(typeof(Button), typeof(CustomButtonRenderer))]
|
||||
namespace Bit.iOS.Controls
|
||||
|
@ -16,25 +17,39 @@ namespace Bit.iOS.Controls
|
|||
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.3f;
|
||||
}
|
||||
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);
|
||||
UpdateFont();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnElementPropertyChanged(sender, e);
|
||||
|
||||
if(e.PropertyName == Button.FontProperty.PropertyName)
|
||||
{
|
||||
UpdateFont();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateFont()
|
||||
{
|
||||
var pointSize = UIFontDescriptor.PreferredBody.PointSize;
|
||||
|
||||
var size = Element.FontSize;
|
||||
if(size == Device.GetNamedSize(NamedSize.Large, typeof(Button)))
|
||||
{
|
||||
pointSize *= 1.3f;
|
||||
}
|
||||
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(Element.Font.ToUIFont().FontDescriptor, pointSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,12 +21,10 @@ namespace Bit.iOS.Controls
|
|||
var view = e.NewElement as ExtendedEntry;
|
||||
if(view != null)
|
||||
{
|
||||
var descriptor = UIFontDescriptor.PreferredBody;
|
||||
Control.Font = UIFont.FromDescriptor( descriptor, descriptor.PointSize );
|
||||
|
||||
SetBorder(view);
|
||||
SetMaxLength(view);
|
||||
UpdateKeyboard();
|
||||
UpdateFont();
|
||||
|
||||
if(view.AllowClear)
|
||||
{
|
||||
|
@ -92,6 +90,39 @@ namespace Bit.iOS.Controls
|
|||
{
|
||||
UpdateKeyboard();
|
||||
}
|
||||
else if(e.PropertyName == Entry.FontAttributesProperty.PropertyName)
|
||||
{
|
||||
UpdateFont();
|
||||
}
|
||||
else if(e.PropertyName == Entry.FontFamilyProperty.PropertyName)
|
||||
{
|
||||
UpdateFont();
|
||||
}
|
||||
else if(e.PropertyName == Entry.FontSizeProperty.PropertyName)
|
||||
{
|
||||
UpdateFont();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateFont()
|
||||
{
|
||||
var pointSize = UIFontDescriptor.PreferredBody.PointSize;
|
||||
|
||||
var size = Element.FontSize;
|
||||
if(size == Device.GetNamedSize(NamedSize.Large, typeof(ExtendedEntry)))
|
||||
{
|
||||
pointSize *= 1.3f;
|
||||
}
|
||||
else if(size == Device.GetNamedSize(NamedSize.Small, typeof(ExtendedEntry)))
|
||||
{
|
||||
pointSize *= .8f;
|
||||
}
|
||||
else if(size == Device.GetNamedSize(NamedSize.Micro, typeof(ExtendedEntry)))
|
||||
{
|
||||
pointSize *= .6f;
|
||||
}
|
||||
|
||||
Control.Font = UIFont.FromName(Element.FontFamily, pointSize);
|
||||
}
|
||||
|
||||
private void SetBorder(ExtendedEntry view)
|
||||
|
|
Loading…
Reference in a new issue