add reveal button to password reprompt on iOS (#1607)

* add reveal button to password reprompt on iOS

* format special chars as unicode
This commit is contained in:
Jake Fink 2021-10-26 17:46:11 -04:00 committed by GitHub
parent b8c1107c94
commit 0e9cbe4539
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 7 deletions

View file

@ -43,7 +43,7 @@ namespace Bit.iOS.Core.Controllers
public abstract Action Cancel { get; } public abstract Action Cancel { get; }
public FormEntryTableViewCell MasterPasswordCell { get; set; } = new FormEntryTableViewCell( public FormEntryTableViewCell MasterPasswordCell { get; set; } = new FormEntryTableViewCell(
AppResources.MasterPassword); AppResources.MasterPassword, useButton: true);
public string BiometricIntegrityKey { get; set; } public string BiometricIntegrityKey { get; set; }
@ -95,6 +95,12 @@ namespace Bit.iOS.Core.Controllers
{ {
MasterPasswordCell.TextField.KeyboardType = UIKeyboardType.NumberPad; 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.RowHeight = UITableView.AutomaticDimension;
TableView.EstimatedRowHeight = 70; TableView.EstimatedRowHeight = 70;

View file

@ -1,16 +1,25 @@
using Bit.iOS.Core.Controllers; using Bit.iOS.Core.Controllers;
using Bit.iOS.Core.Utilities; using Bit.iOS.Core.Utilities;
using System; using System;
using System.Drawing;
using UIKit; using UIKit;
namespace Bit.iOS.Core.Views namespace Bit.iOS.Core.Views
{ {
public class FormEntryTableViewCell : ExtendedUITableViewCell, ISelectable 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( public FormEntryTableViewCell(
string labelName = null, string labelName = null,
bool useTextView = false, bool useTextView = false,
nfloat? height = null, nfloat? height = null,
bool useButton = false,
bool useLabelAsPlaceholder = false, bool useLabelAsPlaceholder = false,
float leadingConstant = 15f) float leadingConstant = 15f)
: base(UITableViewCellStyle.Default, nameof(FormEntryTableViewCell)) : base(UITableViewCellStyle.Default, nameof(FormEntryTableViewCell))
@ -103,7 +112,7 @@ namespace Bit.iOS.Core.Views
ContentView.Add(TextField); ContentView.Add(TextField);
ContentView.AddConstraints(new NSLayoutConstraint[] { ContentView.AddConstraints(new NSLayoutConstraint[] {
NSLayoutConstraint.Create(TextField, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, ContentView, NSLayoutAttribute.Leading, 1f, leadingConstant), 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) 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) NSLayoutConstraint.Create(ContentView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, Label, NSLayoutAttribute.Trailing, 1f, 15f)
}); });
} }
}
public UILabel Label { get; set; } if (useButton)
public UITextField TextField { get; set; } {
public UITextView TextView { get; set; } Button = new UIButton(UIButtonType.System);
public event EventHandler ValueChanged; 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() public void Select()
{ {