Skip to content

Commit

Permalink
fix: IsTabStop handling for TextBox on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Jan 12, 2022
1 parent a0bd585 commit 276d195
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,29 +411,37 @@ private static TypefaceStyle GetTypefaceStyle(FontStyle fontStyle, FontWeight fo
return style;
}

partial void OnIsReadonlyChangedPartial(DependencyPropertyChangedEventArgs e)
partial void OnIsReadonlyChangedPartial(DependencyPropertyChangedEventArgs e) => UpdateTextBoxViewReadOnly();

partial void OnIsTabStopChangedPartial() => UpdateTextBoxViewReadOnly();

private void UpdateTextBoxViewReadOnly()
{
if (_textBoxView != null)
if (_textBoxView == null)
{
var isReadOnly = IsReadOnly;
return;
}

_textBoxView.Focusable = !isReadOnly;
_textBoxView.FocusableInTouchMode = !isReadOnly;
_textBoxView.Clickable = !isReadOnly;
_textBoxView.LongClickable = !isReadOnly;
_textBoxView.SetCursorVisible(!isReadOnly);
// Both IsReadOnly = true and IsTabStop = false make the control
// not receive any input.
var isReadOnly = IsReadOnly || !IsTabStop;

if (isReadOnly)
{
_listener = _textBoxView.KeyListener;
_textBoxView.KeyListener = null;
}
else
_textBoxView.Focusable = !isReadOnly;
_textBoxView.FocusableInTouchMode = !isReadOnly;
_textBoxView.Clickable = !isReadOnly;
_textBoxView.LongClickable = !isReadOnly;
_textBoxView.SetCursorVisible(!isReadOnly);

if (isReadOnly)
{
_listener = _textBoxView.KeyListener;
_textBoxView.KeyListener = null;
}
else
{
if (_listener != null)
{
if (_listener != null)
{
_textBoxView.KeyListener = _listener;
}
_textBoxView.KeyListener = _listener;
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,14 @@ public TextAlignment TextAlignment

#endregion

private protected override void OnIsTabStopChanged(bool oldValue, bool newValue)
{
base.OnIsTabStopChanged(oldValue, newValue);
OnIsTabStopChangedPartial();
}

partial void OnIsTabStopChangedPartial();

internal override void UpdateFocusState(FocusState focusState)
{
var oldValue = FocusState;
Expand Down

0 comments on commit 276d195

Please sign in to comment.