add hide/show password in login and register page
continuous-integration/drone/push Build is passing Details

master
Maxime BATISTA 2 years ago
parent b84f846575
commit e25a1042b2

@ -20,7 +20,7 @@ namespace ShoopNCook.Controllers
public void Logout()
{
UserNotifier.Notice("You have been loged out.");
UserNotifier.Notice("You have been logged out.");
app.ForceLogin();
}

@ -60,12 +60,14 @@
Grid.Column="2"
Placeholder="Password"
x:Name="PasswordEntry"
IsPassword="True"/>
IsPassword="{Binding PasswordHide}"/>
<ImageButton
Grid.Column="3"
Source="visibility_off.svg"
HeightRequest="30">
</ImageButton>
HeightRequest="30"
x:Name="PasswordReveal"
Clicked="OnPasswordRevealClicked"/>
</Grid>
</Border>

@ -6,9 +6,18 @@ namespace ShoopNCook.Pages;
public partial class LoginPage : ContentPage
{
private readonly LoginController controller;
private readonly BindableProperty PasswordHideProperty = BindableProperty.Create(nameof(PasswordHide), typeof(bool), typeof(LoginPage), false);
public bool PasswordHide {
get => (bool) GetValue(PasswordHideProperty);
private set => SetValue(PasswordHideProperty, value);
}
public LoginPage(LoginController controller)
{
InitializeComponent();
BindingContext = this;
SetPasswordHide(true);
this.controller = controller;
}
private void OnLoginButtonClicked(object sender, EventArgs e)
@ -22,4 +31,19 @@ public partial class LoginPage : ContentPage
{
await Shell.Current.GoToAsync("//Register");
}
private void OnPasswordRevealClicked(object sender, EventArgs e)
{
SetPasswordHide(!PasswordHide);
}
public void SetPasswordHide(bool shown)
{
PasswordHide = shown;
if (shown)
PasswordReveal.Source = ImageSource.FromFile("visibility_off.svg");
else
PasswordReveal.Source = ImageSource.FromFile("visibility_on.svg");
}
}

@ -80,11 +80,13 @@
Grid.Column="2"
Placeholder="Password"
x:Name="PasswordEntry"
IsPassword="True"/>
IsPassword="{Binding PasswordHide}"/>
<ImageButton
Grid.Column="3"
Source="visibility_off.svg"
HeightRequest="30"/>
HeightRequest="30"
x:Name="PasswordReveal"
Clicked="OnPasswordRevealClicked"/>
</Grid>
</Border>

@ -5,9 +5,20 @@ namespace ShoopNCook.Pages;
public partial class RegisterPage : ContentPage
{
private readonly RegisterController controller;
private readonly BindableProperty PasswordHideProperty = BindableProperty.Create(nameof(PasswordHide), typeof(bool), typeof(LoginPage), false);
public bool PasswordHide
{
get => (bool)GetValue(PasswordHideProperty);
private set => SetValue(PasswordHideProperty, value);
}
public RegisterPage(RegisterController controller)
{
InitializeComponent();
BindingContext = this;
SetPasswordHide(true);
this.controller = controller;
}
private async void LoginTapped(object sender, EventArgs e)
@ -21,4 +32,19 @@ public partial class RegisterPage : ContentPage
string username = UserNameEntry.Text;
controller.Register(username, email, password);
}
private void OnPasswordRevealClicked(object sender, EventArgs e)
{
SetPasswordHide(!PasswordHide);
}
public void SetPasswordHide(bool shown)
{
PasswordHide = shown;
if (shown)
PasswordReveal.Source = ImageSource.FromFile("visibility_off.svg");
else
PasswordReveal.Source = ImageSource.FromFile("visibility_on.svg");
}
}
Loading…
Cancel
Save