/
TextFieldPasswordShowHideAttachment.cs
66 lines (55 loc) · 1.58 KB
/
TextFieldPasswordShowHideAttachment.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
using Microsoft.Maui.Controls.Shapes;
using UraniumUI.Extensions;
using UraniumUI.Pages;
using UraniumUI.Resources;
using UraniumUI.Views;
using Path = Microsoft.Maui.Controls.Shapes.Path;
namespace UraniumUI.Material.Controls;
public class TextFieldPasswordShowHideAttachment : StatefulContentView
{
public TextField TextField { get; protected set; }
public TextFieldPasswordShowHideAttachment()
{
VerticalOptions = LayoutOptions.Center;
Padding = new Thickness(5, 0);
Margin = new Thickness(0, 0, 5, 0);
TappedCommand = new Command(SwitchPassword);
}
protected override void OnParentSet()
{
TextField = this.FindInParents<TextField>();
if (TextField == null)
{
return;
}
UpdateIcon();
}
protected virtual void SwitchPassword(object parameter)
{
if (TextField is null)
{
UpdateIcon();
return;
}
TextField.IsPassword = !TextField.IsPassword;
UpdateIcon();
}
protected void UpdateIcon()
{
if (TextField is null)
{
Content = null;
return;
}
Content = TextField.IsPassword ? GetPathFromData(UraniumShapes.Eye) : GetPathFromData(UraniumShapes.EyeSlash);
}
private Path GetPathFromData(Geometry data)
{
return new Path
{
Fill = ColorResource.GetColor("OnBackground", "OnBackgroundDark", Colors.DarkGray).WithAlpha(.5f),
VerticalOptions = LayoutOptions.Center,
Data = data,
};
}
}