bitwarden-android/src/Android/Controls/ExtendedButtonRenderer.cs

63 lines
1.8 KiB
C#
Raw Normal View History

using System;
using System.ComponentModel;
using Bit.Android.Controls;
using Bit.App.Controls;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(ExtendedButton), typeof(ExtendedButtonRenderer))]
namespace Bit.Android.Controls
{
2016-08-23 01:59:15 +03:00
public class ExtendedButtonRenderer : CustomButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
SetPadding();
SetUppercase();
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if(e.PropertyName == ExtendedButton.PaddingProperty.PropertyName)
{
SetPadding();
}
else if(e.PropertyName == ExtendedButton.UppercaseProperty.PropertyName)
{
SetUppercase();
}
}
private void SetPadding()
{
var element = Element as ExtendedButton;
if(element != null)
{
Control.SetPadding(
(int)element.Padding.Left,
(int)element.Padding.Top,
(int)element.Padding.Right,
(int)element.Padding.Bottom);
}
}
private void SetUppercase()
{
var element = Element as ExtendedButton;
2016-08-24 07:07:46 +03:00
if(element != null && !string.IsNullOrWhiteSpace(element.Text))
{
2016-08-24 07:07:46 +03:00
if(element.Uppercase)
{
element.Text = element.Text.ToUpperInvariant();
}
else
{
Control.TransformationMethod = null;
}
}
}
}
}