Skip to content

Commit

Permalink
feat: (macOS) Update PasswordBox implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpinedam committed May 4, 2020
1 parent fc06be3 commit a087a21
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 31 deletions.
29 changes: 11 additions & 18 deletions src/Uno.UI/UI/Xaml/Controls/PasswordBox/PasswordBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ public partial class PasswordBox : TextBox
private Button _revealButton;
private readonly SerialDisposable _revealButtonSubscription = new SerialDisposable();

public PasswordBox()
#if __MACOS__
: base(true)
#endif
{

}
public PasswordBox() : base(true) { }

protected override void OnLoaded()
{
Expand Down Expand Up @@ -134,13 +128,11 @@ public override string GetAccessibilityInnerText()
return null;
}

#region IsPasswordRevealButtonEnabled DependencyProperty
public bool IsPasswordRevealButtonEnabled
{
get => (bool)this.GetValue(IsPasswordRevealButtonEnabledProperty);
set
{
this.SetValue(IsPasswordRevealButtonEnabledProperty, value);
}
set => this.SetValue(IsPasswordRevealButtonEnabledProperty, value);
}

public static readonly DependencyProperty IsPasswordRevealButtonEnabledProperty =
Expand All @@ -157,19 +149,20 @@ public bool IsPasswordRevealButtonEnabled
private void OnIsPasswordRevealButtonEnabledChanged(DependencyPropertyChangedEventArgs e)
{
_isButtonEnabled = IsPasswordRevealButtonEnabled;
UpdateButtonStates();
}

private void UpdateButtonStates()
{
if(IsPasswordRevealButtonEnabled)
if (IsPasswordRevealButtonEnabled)
{
VisualStateManager.GoToState(this, "ButtonVisible", true);
VisualStateManager.GoToState(this, TextBoxConstants.ButtonVisibleStateName, true);
}
else
{
VisualStateManager.GoToState(this, "ButtonCollapsed", true);
VisualStateManager.GoToState(this, TextBoxConstants.ButtonCollapsedStateName, true);
}

OnIsPasswordRevealButtonEnabledChangedPartial(e);
}

partial void OnIsPasswordRevealButtonEnabledChangedPartial(DependencyPropertyChangedEventArgs e);
#endregion
}
}
18 changes: 5 additions & 13 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,20 @@ public class TextBoxConstants
public const string ContentElementPartName = "ContentElement";
public const string PlaceHolderPartName = "PlaceholderTextContentPresenter";
public const string DeleteButtonPartName = "DeleteButton";
public const string ButtonVisibleStateName = "ButtonVisible";
public const string ButtonCollapsedStateName = "ButtonCollapsed";
}

public partial class TextBox : Control, IFrameworkTemplatePoolAware
{
private const string ButtonVisibleStateName = "ButtonVisible";
private const string ButtonCollapsedStateName = "ButtonCollapsed";

#pragma warning disable CS0067, CS0649
private IFrameworkElement _placeHolder;
private ContentControl _contentElement;
private WeakReference<Button> _deleteButton;
#pragma warning restore CS0067, CS0649

private ContentPresenter _header;
private bool _isPassword;
protected bool _isButtonEnabled = true;
protected private bool _isButtonEnabled = true;

public event TextChangedEventHandler TextChanged;
public event TypedEventHandler<TextBox, TextBoxTextChangingEventArgs> TextChanging;
Expand Down Expand Up @@ -72,18 +70,12 @@ public partial class TextBox : Control, IFrameworkTemplatePoolAware

public TextBox()
{
_isPassword = false;
InitializeVisualStates();
this.RegisterParentChangedCallback(this, OnParentChanged);
}

private void OnParentChanged(object instance, object key, DependencyObjectParentChangedEventArgs args) => UpdateFontPartial();

protected TextBox(bool isPassword)
{
_isPassword = isPassword;
}

private void InitializeProperties()
{
UpdatePlaceholderVisibility();
Expand Down Expand Up @@ -666,11 +658,11 @@ private void UpdateButtonStates()
// TODO (https://github.com/unoplatform/uno/issues/683): && ActualWidth >= TDB / Note: We also have to invoke this method on SizeChanged
)
{
VisualStateManager.GoToState(this, ButtonVisibleStateName, true);
VisualStateManager.GoToState(this, TextBoxConstants.ButtonVisibleStateName, true);
}
else
{
VisualStateManager.GoToState(this, ButtonCollapsedStateName, true);
VisualStateManager.GoToState(this, TextBoxConstants.ButtonCollapsedStateName, true);
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.macOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ namespace Windows.UI.Xaml.Controls
{
public partial class TextBox
{
private bool _isPassword;
private ITextBoxView _textBoxView;

protected TextBox(bool isPassword)
{
_isPassword = isPassword;
}

partial void InitializePropertiesPartial()
{
OnTextAlignmentChanged(CreateInitialValueChangerEventArgs(TextAlignmentProperty, null, TextAlignment));
Expand Down

0 comments on commit a087a21

Please sign in to comment.