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

Fix multiline InputType on IEditor #3084

Merged
merged 2 commits into from Oct 22, 2021
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
44 changes: 8 additions & 36 deletions src/Core/src/Platform/Android/EditTextExtensions.cs
Expand Up @@ -297,15 +297,15 @@ static int GetSelectionEnd(AppCompatEditText editText, IEntry entry, int start)
return end;
}

internal static void SetInputType(this AppCompatEditText editText, IEditor editor)
internal static void SetInputType(this AppCompatEditText editText, ITextInput textInput)
{
if (editor.IsReadOnly)
if (textInput.IsReadOnly)
{
editText.InputType = InputTypes.Null;
}
else
{
var keyboard = editor.Keyboard;
var keyboard = textInput.Keyboard;
var nativeInputTypeToUpdate = keyboard.ToInputType();

if (keyboard is not CustomKeyboard)
Expand All @@ -314,7 +314,7 @@ internal static void SetInputType(this AppCompatEditText editText, IEditor edito

if ((nativeInputTypeToUpdate & InputTypes.TextFlagNoSuggestions) != InputTypes.TextFlagNoSuggestions)
{
if (!editor.IsTextPredictionEnabled)
if (!textInput.IsTextPredictionEnabled)
nativeInputTypeToUpdate |= InputTypes.TextFlagNoSuggestions;
}
}
Expand All @@ -324,38 +324,7 @@ internal static void SetInputType(this AppCompatEditText editText, IEditor edito
editText.KeyListener = LocalizedDigitsKeyListener.Create(editText.InputType);
}

editText.InputType = nativeInputTypeToUpdate;
}
}

internal static void SetInputType(this AppCompatEditText editText, IEntry entry)
{
if (entry.IsReadOnly)
{
editText.InputType = InputTypes.Null;
}
else
{
var keyboard = entry.Keyboard;
var nativeInputTypeToUpdate = keyboard.ToInputType();

if (keyboard is not CustomKeyboard)
{
// TODO: IsSpellCheckEnabled handling must be here.

if ((nativeInputTypeToUpdate & InputTypes.TextFlagNoSuggestions) != InputTypes.TextFlagNoSuggestions)
{
if (!entry.IsTextPredictionEnabled)
nativeInputTypeToUpdate |= InputTypes.TextFlagNoSuggestions;
}
}

if (keyboard == Keyboard.Numeric)
{
editText.KeyListener = LocalizedDigitsKeyListener.Create(editText.InputType);
}

if (entry.IsPassword)
if (textInput is IEntry entry && entry.IsPassword)
{
if ((nativeInputTypeToUpdate & InputTypes.ClassText) == InputTypes.ClassText)
nativeInputTypeToUpdate |= InputTypes.TextVariationPassword;
Expand All @@ -366,6 +335,9 @@ internal static void SetInputType(this AppCompatEditText editText, IEntry entry)

editText.InputType = nativeInputTypeToUpdate;
}

if (textInput is IEditor)
editText.InputType |= InputTypes.TextFlagMultiLine;
}
}
}
Expand Up @@ -14,6 +14,30 @@ namespace Microsoft.Maui.DeviceTests
{
public partial class EditorHandlerTests
{
[Fact(DisplayName = "InputType Keeps MultiLine Flag")]
public async Task InputTypeKeepsMultiLineFlag()
{
var editor = new EditorStub();
var inputType = await GetValueAsync(editor, (handler) =>
{
return GetNativeEditor(handler).InputType;
});

Assert.True(inputType.HasFlag(InputTypes.TextFlagMultiLine));
}

[Fact(DisplayName = "ReadOnly Keeps MultiLine Flag")]
public async Task InputTypeInitializesWithMultiLineFlag()
{
var editor = new EditorStub() { IsReadOnly = true };
var inputType = await GetValueAsync(editor, (handler) =>
{
return GetNativeEditor(handler).InputType;
});

Assert.True(inputType.HasFlag(InputTypes.TextFlagMultiLine));
}

[Fact(DisplayName = "CharacterSpacing Initializes Correctly")]
public async Task CharacterSpacingInitializesCorrectly()
{
Expand Down