Skip to content

Commit

Permalink
fix(passwordbox): reveal button not working
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Apr 1, 2024
1 parent 76e0808 commit 17b8c82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 14 additions & 11 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBoxView.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ internal class TextBoxView

public TextBoxView(TextBox textBox)
{
_textBox = new WeakReference<TextBox>(textBox);
_isPasswordBox = textBox is PasswordBox;

DisplayBlock = new TextBlock();
SetFlowDirectionAndTextAlignment();

_textBox = new WeakReference<TextBox>(textBox);
_isPasswordBox = textBox is PasswordBox;
if (!_isSkiaTextBox && !ApiExtensibility.CreateInstance(this, out _textBoxExtension))
{
if (this.Log().IsEnabled(LogLevel.Warning))
Expand Down Expand Up @@ -63,7 +64,7 @@ public TextBox? TextBox

internal void SetTextNative(string text)
{
SetDisplayBlockText(text);
UpdateDisplayBlockText(text);

_textBoxExtension?.SetText(text);
}
Expand All @@ -75,7 +76,7 @@ internal void Select(int start, int length)

internal void SetFlowDirectionAndTextAlignment()
{
if (_textBox?.GetTarget() is not { } textBox)
if (TextBox is not { } textBox)
{
return;
}
Expand All @@ -98,7 +99,7 @@ internal void SetFlowDirectionAndTextAlignment()

internal void SetWrapping()
{
if (_textBox?.GetTarget() is { } textBox)
if (TextBox is { } textBox)
{
DisplayBlock.TextWrapping = textBox.TextWrapping;
}
Expand Down Expand Up @@ -146,8 +147,7 @@ internal void OnFocusStateChanged(FocusState focusState)

internal void UpdateFont()
{
var textBox = _textBox?.GetTarget();
if (textBox != null)
if (TextBox is { } textBox)
{
DisplayBlock.FontFamily = textBox.FontFamily;
DisplayBlock.FontSize = textBox.FontSize;
Expand All @@ -162,17 +162,20 @@ internal void SetPasswordRevealState(PasswordRevealState revealState)
{
_isPasswordRevealed = revealState == PasswordRevealState.Revealed;
_textBoxExtension?.SetPasswordRevealState(revealState);
if (TextBox is { } textBox)
{
UpdateDisplayBlockText(textBox.Text);
}
}

internal void UpdateTextFromNative(string newText)
{
var textBox = _textBox?.GetTarget();
if (textBox != null)
if (TextBox is { } textBox)
{
var oldText = textBox.Text; // preexisting text
var oldSelection = SelectionBeforeKeyDown; // On Gtk, SelectionBeforeKeyDown just points to Selection, which is updated by SetTextNative, so we need to read it before SetTextNative.
var modifiedText = textBox.ProcessTextInput(newText); // new text after BeforeTextChanging, TextChanging, DP callback, etc
SetDisplayBlockText(modifiedText);
UpdateDisplayBlockText(modifiedText);
if (modifiedText != newText)
{
SetTextNative(modifiedText);
Expand All @@ -195,7 +198,7 @@ internal void UpdateTextFromNative(string newText)

public void UpdateMaxLength() => _textBoxExtension?.UpdateNativeView();

private void SetDisplayBlockText(string text)
private void UpdateDisplayBlockText(string text)
{
// TODO: Inheritance hierarchy is wrong in Uno. PasswordBox shouldn't inherit TextBox.
// This needs to be moved to PasswordBox if it's separated from TextBox.
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Documents/InlineCollection.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ internal void InvalidateMeasure()
internal void Draw(in DrawingSession session)
{
var newDrawingState = (_selection, CaretAtEndOfSelection, RenderSelection, RenderCaret);
var somethingChanged = _drawingValid is not { wentThroughDraw: true, wentThroughMeasure: true } && !_lastDrawingState.Equals(newDrawingState);
var somethingChanged = _drawingValid is not { wentThroughDraw: true, wentThroughMeasure: true } || !_lastDrawingState.Equals(newDrawingState);
var fireEvents = FireDrawingEventsOnEveryRedraw || somethingChanged;
_drawingValid.wentThroughDraw = true;
_lastDrawingState = newDrawingState;
Expand Down

0 comments on commit 17b8c82

Please sign in to comment.