Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] [TextBox] fix a bug which cause cannot call out the soft keyboard again after closing it #15603

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Avalonia.Base/Input/TextInput/TextInputMethodClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public virtual void SetPreeditText(string? preeditText, int? cursorPos)
{
SetPreeditText(preeditText);
}

public virtual void ShowInputPanel() { }

protected virtual void RaiseTextViewVisualChanged()
{
Expand Down
2 changes: 2 additions & 0 deletions src/Avalonia.Controls/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,8 @@ protected override void OnPointerReleased(PointerReleasedEventArgs e)

if (e.Pointer.Type != PointerType.Mouse && !_isDoubleTapped)
{
_imClient.ShowInputPanel();

var text = Text;
var clickInfo = e.GetCurrentPoint(this);
if (text != null && !(clickInfo.Pointer?.Captured is Border))
Expand Down
23 changes: 20 additions & 3 deletions src/Avalonia.Controls/TextBoxTextInputMethodClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal class TextBoxTextInputMethodClient : TextInputMethodClient
private TextPresenter? _presenter;
private bool _selectionChanged;
private bool _isInChange;
private ITextInputMethodImpl? _im;

public override Visual TextViewVisual => _presenter!;

Expand All @@ -24,7 +25,7 @@ public override string SurroundingText
{
return "";
}

if (_parent.CaretIndex != _presenter.CaretIndex)
{
_presenter.SetCurrentValue(TextPresenter.CaretIndexProperty, _parent.CaretIndex);
Expand All @@ -34,7 +35,7 @@ public override string SurroundingText
{
_presenter.SetCurrentValue(TextPresenter.TextProperty, _parent.Text);
}

var lineIndex = _presenter.TextLayout.GetLineIndexFromCharacterIndex(_presenter.CaretIndex, false);

var textLine = _presenter.TextLayout.TextLines[lineIndex];
Expand Down Expand Up @@ -125,6 +126,11 @@ public void SetPresenter(TextPresenter? presenter, TextBox? parent)
if (_parent != null)
{
_parent.PropertyChanged += OnParentPropertyChanged;
_im = (_parent.VisualRoot as ITextInputMethodRoot)?.InputMethod;
}
else
{
_im = null;
}

var oldPresenter = _presenter;
Expand All @@ -133,7 +139,7 @@ public void SetPresenter(TextPresenter? presenter, TextBox? parent)
{
oldPresenter.ClearValue(TextPresenter.PreeditTextProperty);

oldPresenter.CaretBoundsChanged -= (s,e) => RaiseCursorRectangleChanged();
oldPresenter.CaretBoundsChanged -= (s, e) => RaiseCursorRectangleChanged();
}

_presenter = presenter;
Expand Down Expand Up @@ -161,6 +167,17 @@ public override void SetPreeditText(string? preeditText, int? cursorPos)
_presenter.SetCurrentValue(TextPresenter.PreeditTextCursorPositionProperty, cursorPos);
}

public override void ShowInputPanel()
{
base.ShowInputPanel();

if (_parent is { } && _im is { })
{
_im.SetOptions(TextInputOptions.FromStyledElement(_parent));
_im.SetClient(this);
}
}

private static string GetTextLineText(TextLine textLine)
{
var builder = StringBuilderCache.Acquire(textLine.Length);
Expand Down