From 0e9cbe4539d8a8ec7de5d10583e6e86596663f8b Mon Sep 17 00:00:00 2001 From: Jake Fink Date: Tue, 26 Oct 2021 17:46:11 -0400 Subject: [PATCH] add reveal button to password reprompt on iOS (#1607) * add reveal button to password reprompt on iOS * format special chars as unicode --- .../Controllers/LockPasswordViewController.cs | 8 ++++- src/iOS.Core/Views/FormEntryTableViewCell.cs | 30 +++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/iOS.Core/Controllers/LockPasswordViewController.cs b/src/iOS.Core/Controllers/LockPasswordViewController.cs index ff11e27bf..bf1701b95 100644 --- a/src/iOS.Core/Controllers/LockPasswordViewController.cs +++ b/src/iOS.Core/Controllers/LockPasswordViewController.cs @@ -43,7 +43,7 @@ namespace Bit.iOS.Core.Controllers public abstract Action Cancel { get; } public FormEntryTableViewCell MasterPasswordCell { get; set; } = new FormEntryTableViewCell( - AppResources.MasterPassword); + AppResources.MasterPassword, useButton: true); public string BiometricIntegrityKey { get; set; } @@ -95,6 +95,12 @@ namespace Bit.iOS.Core.Controllers { MasterPasswordCell.TextField.KeyboardType = UIKeyboardType.NumberPad; } + MasterPasswordCell.Button.TitleLabel.Font = UIFont.FromName("FontAwesome", 28f); + MasterPasswordCell.Button.SetTitle("\uf06e", UIControlState.Normal); + MasterPasswordCell.Button.TouchUpInside += (sender, e) => { + MasterPasswordCell.TextField.SecureTextEntry = !MasterPasswordCell.TextField.SecureTextEntry; + MasterPasswordCell.Button.SetTitle(MasterPasswordCell.TextField.SecureTextEntry ? "\uf06e" : "\uf070", UIControlState.Normal); + }; TableView.RowHeight = UITableView.AutomaticDimension; TableView.EstimatedRowHeight = 70; diff --git a/src/iOS.Core/Views/FormEntryTableViewCell.cs b/src/iOS.Core/Views/FormEntryTableViewCell.cs index 1172fa87e..9ebc25a6d 100644 --- a/src/iOS.Core/Views/FormEntryTableViewCell.cs +++ b/src/iOS.Core/Views/FormEntryTableViewCell.cs @@ -1,16 +1,25 @@ using Bit.iOS.Core.Controllers; using Bit.iOS.Core.Utilities; using System; +using System.Drawing; using UIKit; namespace Bit.iOS.Core.Views { public class FormEntryTableViewCell : ExtendedUITableViewCell, ISelectable { + public UILabel Label { get; set; } + public UITextField TextField { get; set; } + public UITextView TextView { get; set; } + public UIButton Button { get; set; } + public event EventHandler ValueChanged; + + public FormEntryTableViewCell( string labelName = null, bool useTextView = false, nfloat? height = null, + bool useButton = false, bool useLabelAsPlaceholder = false, float leadingConstant = 15f) : base(UITableViewCellStyle.Default, nameof(FormEntryTableViewCell)) @@ -103,7 +112,7 @@ namespace Bit.iOS.Core.Views ContentView.Add(TextField); ContentView.AddConstraints(new NSLayoutConstraint[] { NSLayoutConstraint.Create(TextField, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Leading, 1f, leadingConstant), - NSLayoutConstraint.Create(ContentView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, TextField, NSLayoutAttribute.Trailing, 1f, 15f), + NSLayoutConstraint.Create(ContentView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, TextField, NSLayoutAttribute.Trailing, 1f, useButton ? 55f : 15f), NSLayoutConstraint.Create(ContentView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, TextField, NSLayoutAttribute.Bottom, 1f, 10f) }); @@ -138,12 +147,21 @@ namespace Bit.iOS.Core.Views NSLayoutConstraint.Create(ContentView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, Label, NSLayoutAttribute.Trailing, 1f, 15f) }); } - } - public UILabel Label { get; set; } - public UITextField TextField { get; set; } - public UITextView TextView { get; set; } - public event EventHandler ValueChanged; + if (useButton) + { + Button = new UIButton(UIButtonType.System); + Button.Frame = ContentView.Bounds; + Button.TranslatesAutoresizingMaskIntoConstraints = false; + Button.SetTitleColor(ThemeHelpers.PrimaryColor, UIControlState.Normal); + + ContentView.Add(Button); + + ContentView.BottomAnchor.ConstraintEqualTo(Button.BottomAnchor, 10f).Active = true; + ContentView.TrailingAnchor.ConstraintEqualTo(Button.TrailingAnchor, 10f).Active = true; + Button.LeadingAnchor.ConstraintEqualTo(TextField.TrailingAnchor, 10f).Active = true; + } + } public void Select() {