mirror of
https://github.com/bitwarden/mobile
synced 2025-12-20 18:23:51 +00:00
Updated PIN lock page with gesture recognizer to refocus entry
This commit is contained in:
@@ -77,10 +77,10 @@ namespace Bit.App
|
|||||||
CheckLockAsync(false);
|
CheckLockAsync(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var lockPage = Current.MainPage.Navigation.ModalStack.LastOrDefault() as LockPinPage;
|
var lockPinPage = Current.MainPage.Navigation.ModalStack.LastOrDefault() as LockPinPage;
|
||||||
if(lockPage != null)
|
if(lockPinPage != null)
|
||||||
{
|
{
|
||||||
lockPage.PinControl.Entry.Focus();
|
lockPinPage.PinControl.Entry.Focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using Bit.App.Models.Page;
|
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace Bit.App.Controls
|
namespace Bit.App.Controls
|
||||||
@@ -7,10 +6,12 @@ namespace Bit.App.Controls
|
|||||||
public class PinControl
|
public class PinControl
|
||||||
{
|
{
|
||||||
private Action _pinEnteredAction;
|
private Action _pinEnteredAction;
|
||||||
|
private Action _confirmPinEnteredAction;
|
||||||
|
|
||||||
public PinControl(Action pinEnteredAction)
|
public PinControl(Action pinEnteredAction, Action confirmPinEnteredAction = null)
|
||||||
{
|
{
|
||||||
_pinEnteredAction = pinEnteredAction;
|
_pinEnteredAction = pinEnteredAction;
|
||||||
|
_confirmPinEnteredAction = confirmPinEnteredAction;
|
||||||
|
|
||||||
Label = new Label
|
Label = new Label
|
||||||
{
|
{
|
||||||
@@ -19,7 +20,6 @@ namespace Bit.App.Controls
|
|||||||
TextColor = Color.FromHex("333333"),
|
TextColor = Color.FromHex("333333"),
|
||||||
FontFamily = "Courier"
|
FontFamily = "Courier"
|
||||||
};
|
};
|
||||||
Label.SetBinding<PinPageModel>(Label.TextProperty, s => s.LabelText);
|
|
||||||
|
|
||||||
Entry = new ExtendedEntry
|
Entry = new ExtendedEntry
|
||||||
{
|
{
|
||||||
@@ -27,19 +27,35 @@ namespace Bit.App.Controls
|
|||||||
MaxLength = 4,
|
MaxLength = 4,
|
||||||
Margin = new Thickness(0, int.MaxValue, 0, 0)
|
Margin = new Thickness(0, int.MaxValue, 0, 0)
|
||||||
};
|
};
|
||||||
Entry.SetBinding<PinPageModel>(Xamarin.Forms.Entry.TextProperty, s => s.PIN);
|
Entry.TextChanged += Entry_TextChanged;
|
||||||
Entry.TextChanged += PinEntry_TextChanged;
|
|
||||||
|
ConfirmEntry = new ExtendedEntry
|
||||||
|
{
|
||||||
|
Keyboard = Keyboard.Numeric,
|
||||||
|
MaxLength = 4,
|
||||||
|
Margin = new Thickness(0, int.MaxValue, 0, 0)
|
||||||
|
};
|
||||||
|
Entry.TextChanged += ConfirmEntry_TextChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PinEntry_TextChanged(object sender, TextChangedEventArgs e)
|
private void Entry_TextChanged(object sender, TextChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if(e.NewTextValue.Length >= 4)
|
if(e.NewTextValue.Length >= 4 && _pinEnteredAction != null)
|
||||||
{
|
{
|
||||||
_pinEnteredAction();
|
_pinEnteredAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ConfirmEntry_TextChanged(object sender, TextChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if(e.NewTextValue.Length >= 4 && _confirmPinEnteredAction != null)
|
||||||
|
{
|
||||||
|
_confirmPinEnteredAction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Label Label { get; set; }
|
public Label Label { get; set; }
|
||||||
public ExtendedEntry Entry { get; set; }
|
public ExtendedEntry Entry { get; set; }
|
||||||
|
public ExtendedEntry ConfirmEntry { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System.ComponentModel;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
|
|
||||||
namespace Bit.App.Models.Page
|
namespace Bit.App.Models.Page
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,10 +6,8 @@ using Bit.App.Resources;
|
|||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
using XLabs.Ioc;
|
using XLabs.Ioc;
|
||||||
using Plugin.Settings.Abstractions;
|
using Plugin.Settings.Abstractions;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Bit.App.Models.Page;
|
using Bit.App.Models.Page;
|
||||||
using Bit.App.Controls;
|
using Bit.App.Controls;
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace Bit.App.Pages
|
namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
@@ -34,6 +32,8 @@ namespace Bit.App.Pages
|
|||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
PinControl = new PinControl(PinEntered);
|
PinControl = new PinControl(PinEntered);
|
||||||
|
PinControl.Label.SetBinding<PinPageModel>(Label.TextProperty, s => s.LabelText);
|
||||||
|
PinControl.Entry.SetBinding<PinPageModel>(Entry.TextProperty, s => s.PIN);
|
||||||
|
|
||||||
var logoutButton = new Button
|
var logoutButton = new Button
|
||||||
{
|
{
|
||||||
@@ -49,11 +49,19 @@ namespace Bit.App.Pages
|
|||||||
Children = { PinControl.Label, logoutButton, PinControl.Entry }
|
Children = { PinControl.Label, logoutButton, PinControl.Entry }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var tgr = new TapGestureRecognizer();
|
||||||
|
tgr.Tapped += Tgr_Tapped;
|
||||||
|
|
||||||
Title = "Verify PIN";
|
Title = "Verify PIN";
|
||||||
Content = stackLayout;
|
Content = stackLayout;
|
||||||
|
Content.GestureRecognizers.Add(tgr);
|
||||||
BindingContext = Model;
|
BindingContext = Model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Tgr_Tapped(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
PinControl.Entry.Focus();
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool OnBackButtonPressed()
|
protected override bool OnBackButtonPressed()
|
||||||
{
|
{
|
||||||
@@ -75,6 +83,8 @@ namespace Bit.App.Pages
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// TODO: keep track of invalid attempts and logout?
|
||||||
|
|
||||||
_userDialogs.Alert("Invalid PIN. Try again.");
|
_userDialogs.Alert("Invalid PIN. Try again.");
|
||||||
Model.PIN = string.Empty;
|
Model.PIN = string.Empty;
|
||||||
PinControl.Entry.Focus();
|
PinControl.Entry.Focus();
|
||||||
|
|||||||
Reference in New Issue
Block a user