1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-09-27 03:52:57 +02:00

Updated PIN lock page with gesture recognizer to refocus entry

This commit is contained in:
Kyle Spearrin 2016-06-07 19:19:21 -04:00
parent a871a839e7
commit 904ba1ffb8
4 changed files with 39 additions and 15 deletions

View File

@ -77,10 +77,10 @@ namespace Bit.App
CheckLockAsync(false);
}
var lockPage = Current.MainPage.Navigation.ModalStack.LastOrDefault() as LockPinPage;
if(lockPage != null)
var lockPinPage = Current.MainPage.Navigation.ModalStack.LastOrDefault() as LockPinPage;
if(lockPinPage != null)
{
lockPage.PinControl.Entry.Focus();
lockPinPage.PinControl.Entry.Focus();
}
}

View File

@ -1,5 +1,4 @@
using System;
using Bit.App.Models.Page;
using Xamarin.Forms;
namespace Bit.App.Controls
@ -7,10 +6,12 @@ namespace Bit.App.Controls
public class PinControl
{
private Action _pinEnteredAction;
private Action _confirmPinEnteredAction;
public PinControl(Action pinEnteredAction)
public PinControl(Action pinEnteredAction, Action confirmPinEnteredAction = null)
{
_pinEnteredAction = pinEnteredAction;
_confirmPinEnteredAction = confirmPinEnteredAction;
Label = new Label
{
@ -19,7 +20,6 @@ namespace Bit.App.Controls
TextColor = Color.FromHex("333333"),
FontFamily = "Courier"
};
Label.SetBinding<PinPageModel>(Label.TextProperty, s => s.LabelText);
Entry = new ExtendedEntry
{
@ -27,19 +27,35 @@ namespace Bit.App.Controls
MaxLength = 4,
Margin = new Thickness(0, int.MaxValue, 0, 0)
};
Entry.SetBinding<PinPageModel>(Xamarin.Forms.Entry.TextProperty, s => s.PIN);
Entry.TextChanged += PinEntry_TextChanged;
Entry.TextChanged += Entry_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();
}
}
private void ConfirmEntry_TextChanged(object sender, TextChangedEventArgs e)
{
if(e.NewTextValue.Length >= 4 && _confirmPinEnteredAction != null)
{
_confirmPinEnteredAction();
}
}
public Label Label { get; set; }
public ExtendedEntry Entry { get; set; }
public ExtendedEntry ConfirmEntry { get; set; }
}
}

View File

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel;
namespace Bit.App.Models.Page
{

View File

@ -6,10 +6,8 @@ using Bit.App.Resources;
using Xamarin.Forms;
using XLabs.Ioc;
using Plugin.Settings.Abstractions;
using System.Collections.Generic;
using Bit.App.Models.Page;
using Bit.App.Controls;
using System.Diagnostics;
namespace Bit.App.Pages
{
@ -34,6 +32,8 @@ namespace Bit.App.Pages
public void Init()
{
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
{
@ -49,11 +49,19 @@ namespace Bit.App.Pages
Children = { PinControl.Label, logoutButton, PinControl.Entry }
};
var tgr = new TapGestureRecognizer();
tgr.Tapped += Tgr_Tapped;
Title = "Verify PIN";
Content = stackLayout;
Content.GestureRecognizers.Add(tgr);
BindingContext = Model;
}
private void Tgr_Tapped(object sender, EventArgs e)
{
PinControl.Entry.Focus();
}
protected override bool OnBackButtonPressed()
{
@ -75,6 +83,8 @@ namespace Bit.App.Pages
}
else
{
// TODO: keep track of invalid attempts and logout?
_userDialogs.Alert("Invalid PIN. Try again.");
Model.PIN = string.Empty;
PinControl.Entry.Focus();