This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
MaterialEntryRenderer.cs
71 lines (58 loc) · 2.19 KB
/
MaterialEntryRenderer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using Android.Content;
using Android.Util;
using Android.Views;
using Android.Widget;
using Xamarin.Forms;
using Xamarin.Forms.Material.Android;
using Xamarin.Forms.Platform.Android;
using AView = Android.Views.View;
namespace Xamarin.Forms.Material.Android
{
public class MaterialEntryRenderer : EntryRendererBase<MaterialFormsTextInputLayout>, ITabStop
{
MaterialFormsEditText _textInputEditText;
MaterialFormsTextInputLayout _textInputLayout;
public MaterialEntryRenderer(Context context) :
base(MaterialContextThemeWrapper.Create(context))
{
}
protected override AView ControlUsedForAutomation => EditText;
protected override MaterialFormsTextInputLayout CreateNativeControl()
{
LayoutInflater inflater = LayoutInflater.FromContext(Context);
var view = inflater.Inflate(Resource.Layout.TextInputLayoutFilledBox, null);
_textInputLayout = (MaterialFormsTextInputLayout)view;
_textInputEditText = _textInputLayout.FindViewById<MaterialFormsEditText>(Resource.Id.materialformsedittext);
return _textInputLayout;
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
UpdateBackgroundColor();
}
protected override void UpdateColor() => ApplyTheme();
protected override void UpdateBackgroundColor()
{
if (_textInputLayout == null)
return;
_textInputLayout.BoxBackgroundColor = MaterialColors.CreateEntryFilledInputBackgroundColor(Element.BackgroundColor, Element.TextColor);
}
protected override void UpdatePlaceHolderText() => _textInputLayout.SetHint(Element.Placeholder, Element);
protected override EditText EditText => _textInputEditText;
protected override void UpdatePlaceholderColor() => ApplyTheme();
void ApplyTheme(Color textColor) => _textInputLayout?.ApplyTheme(textColor, Element.PlaceholderColor);
void ApplyTheme() => ApplyTheme(Element.TextColor);
protected override void UpdateTextColor(Color color)
{
ApplyTheme(color);
}
protected override void UpdateFont()
{
base.UpdateFont();
_textInputLayout.Typeface = Element.ToTypeface();
_textInputEditText.SetTextSize(ComplexUnitType.Sp, (float)Element.FontSize);
}
AView ITabStop.TabStop => EditText;
}
}