Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
VerifyCodePage.xaml.cs
1using CommunityToolkit.Maui.Core.Platform;
2using CommunityToolkit.Mvvm.Messaging;
3using Microsoft.Maui.Controls.PlatformConfiguration;
4using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
6
8{
9 public partial class VerifyCodePage
10 {
11 private readonly List<Label> innerLabels;
12
17 {
18 this.InitializeComponent();
19
20 VerifyCodeViewModel ViewModel = new(ServiceRef.NavigationService.PopLatestArgs<VerifyCodeNavigationArgs>());
21 this.ContentPageModel = ViewModel;
22
23 this.innerLabels = [
24 this.InnerCode1,
25 this.InnerCode2,
26 this.InnerCode3,
27 this.InnerCode4,
28 this.InnerCode5,
29 this.InnerCode6
30 ];
31
32 this.InnerCodeEntry.Text = string.Empty;
33 }
34
36 public override async Task OnAppearingAsync()
37 {
38 await base.OnAppearingAsync();
39 }
40
42 public override async Task OnDisappearingAsync()
43 {
44 await base.OnDisappearingAsync();
45 }
46
47 private async void InnerCodeEntry_TextChanged(object? Sender, TextChangedEventArgs e)
48 {
49 string NewText = e.NewTextValue;
50 int NewLength = NewText.Length;
51
52 bool IsValid = (NewLength <= this.innerLabels.Count) || NewText.ToCharArray().All(ch => !"0123456789".Contains(ch));
53
54 if (!IsValid)
55 {
56 this.InnerCodeEntry.Text = e.OldTextValue;
57 return;
58 }
59
60 for (int i = 0; i < this.innerLabels.Count; i++)
61 {
62 if (NewLength > i)
63 {
64 this.innerLabels[i].Text = NewText[i..(i + 1)];
65 VisualStateManager.GoToState(this.innerLabels[i], VisualStateManager.CommonStates.Normal);
66 }
67 else
68 {
69 this.innerLabels[i].Text = "0\u2060"; // Added a "zero width no-break space" to make the disabled state to work right :)
70 VisualStateManager.GoToState(this.innerLabels[i], VisualStateManager.CommonStates.Disabled);
71 }
72 }
73
74 if (NewLength == this.innerLabels.Count)
75 await this.InnerCodeEntry.HideKeyboardAsync();
76 }
77
78 private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
79 {
80 this.InnerCodeEntry.Focus();
81 }
82 }
83}
Base class that references services in the app.
Definition: ServiceRef.cs:43
static INavigationService NavigationService
The navigation service for navigating between pages.
Definition: ServiceRef.cs:178
VerifyCodePage()
Creates a new instance of the VerifyCodePage class.
The view model to bind to when verifying a code.