-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathLoginPage.cs
84 lines (68 loc) · 3.46 KB
/
LoginPage.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
72
73
74
75
76
77
78
79
80
81
82
83
84
using CSharpForMarkup;
using Xamarin.Forms;
using Xamarin.Forms.Shapes;
using static CSharpForMarkup.EnumsForGridRowsAndColumns;
using static Xappy.Content.Scenarios.Login.LoginPageExtensions;
namespace Xappy.Content.Scenarios.Login
{
// Markup
public partial class LoginPage : ContentPage
{
enum Row { Avatar, Controls, ToggleMode }
// note that the .Assign statements are only needed for the animation code in LoginPage.logic.cs;
// otherwise this markup could be even cleaner
void Build() => Content = new ScrollView { Content =
new Grid {
RowDefinitions = Rows.Define (
(Row.Avatar , 140),
(Row.Controls , Auto),
(Row.ToggleMode, Auto)
),
Children = {
new Image { Clip = new EllipseGeometry(new Point(70,70),70,70) }
.Assign (out AvatarImage)
.Row (Row.Avatar) .Center () .Size (140)
.Bind (nameof(ViewModel.AvatarUri)),
LoginControls_Declarative
.Assign (out LoginControls)
.Row (Row.Controls),
SignupControls_DSL
.Assign (out SignupControls)
.Row (Row.Controls),
new ActivityIndicator { }
.Bind (nameof(ViewModel.IsBusy)),
}
} .Assign (out MainGrid)
.Center () .Margin (20)
};
// returns the controls for the login form in a declarative, CSharpForMarkup manner
// this style balances conciseness, consistency and reusability
StackLayout LoginControls_Declarative => new StackLayout { Children = {
new Entry { Placeholder = "Username" }
.Bind (nameof(ViewModel.Username)),
new Entry { Placeholder = "Password", IsPassword = true }
.Bind (nameof(ViewModel.Password)),
new Button { Text = "Log in", Command = ViewModel.LoginCommand }
.Bind (IsEnabledProperty, nameof(IsBusy), converter: BoolNotConverter.Instance),
new Label { Text = "Have an account? Log in" } .FontSize (18) .FormattedText (
new Span { Text = "New User? " },
new Span { Text = "Sign up", TextColor = Color.Blue, TextDecorations = TextDecorations.Underline }
.BindTap (nameof(ViewModel.ToggleModeCommand))
) .CenterH () .Margin (12)
} };
// returns ths controls for the login form in using a dedicated DSL syntax for the page
// this format is concise and readable, but potentially specific to the page or app
StackLayout SignupControls_DSL => Stack (
Entry ("Username", nameof(ViewModel.Username)),
Validation (nameof(ViewModel.UsernameValidation)),
Entry ("Email Address", nameof(ViewModel.EmailAddress)),
Validation (nameof(ViewModel.EmailAddressValidation)),
Entry ("Password", nameof(ViewModel.Password), true),
Validation (nameof(ViewModel.PasswordValidation)),
Entry ("Confirm Password", nameof(ViewModel.ConfirmPassword), true),
Validation (nameof(ViewModel.ConfirmPasswordValidation)),
Button ("Sign up", ViewModel.SignupCommand),
Link ("Have an account? ", "Log in", nameof(ViewModel.ToggleModeCommand))
);
}
}