Android: add support for TextInputType.none (flutter/engine#26585)

This commit is contained in:
J-P Nurmi
2021-06-29 18:51:01 +02:00
committed by GitHub
parent 9e3b487842
commit ab0e02d988
3 changed files with 78 additions and 6 deletions

View File

@@ -640,7 +640,8 @@ public class TextInputChannel {
MULTILINE("TextInputType.multiline"),
EMAIL_ADDRESS("TextInputType.emailAddress"),
URL("TextInputType.url"),
VISIBLE_PASSWORD("TextInputType.visiblePassword");
VISIBLE_PASSWORD("TextInputType.visiblePassword"),
NONE("TextInputType.none");
static TextInputType fromValue(@NonNull String encodedName) throws NoSuchFieldException {
for (TextInputType textInputType : TextInputType.values()) {

View File

@@ -244,6 +244,8 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch
return textType;
} else if (type.type == TextInputChannel.TextInputType.PHONE) {
return InputType.TYPE_CLASS_PHONE;
} else if (type.type == TextInputChannel.TextInputType.NONE) {
return InputType.TYPE_NULL;
}
int textType = InputType.TYPE_CLASS_TEXT;
@@ -365,9 +367,21 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch
mImm.sendAppPrivateCommand(mView, action, data);
}
private void showTextInput(View view) {
view.requestFocus();
mImm.showSoftInput(view, 0);
private boolean canShowTextInput() {
if (configuration == null || configuration.inputType == null) {
return true;
}
return configuration.inputType.type != TextInputChannel.TextInputType.NONE;
}
@VisibleForTesting
void showTextInput(View view) {
if (canShowTextInput()) {
view.requestFocus();
mImm.showSoftInput(view, 0);
} else {
hideTextInput(view);
}
}
private void hideTextInput(View view) {
@@ -385,7 +399,12 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch
void setTextInputClient(int client, TextInputChannel.Configuration configuration) {
// Call notifyViewExited on the previous field.
notifyViewExited();
inputTarget = new InputTarget(InputTarget.Type.FRAMEWORK_CLIENT, client);
this.configuration = configuration;
if (canShowTextInput()) {
inputTarget = new InputTarget(InputTarget.Type.FRAMEWORK_CLIENT, client);
} else {
inputTarget = new InputTarget(InputTarget.Type.NO_TARGET, client);
}
if (mEditable != null) {
mEditable.removeEditingStateListener(this);
@@ -393,7 +412,6 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch
mEditable =
new ListenableEditingState(
configuration.autofill != null ? configuration.autofill.editState : null, mView);
this.configuration = configuration;
updateAutofillConfigurationIfNeeded(configuration);
// setTextInputClient will be followed by a call to setTextInputEditingState.

View File

@@ -604,6 +604,59 @@ public class TextInputPluginTest {
assertEquals(0, testImm.getLastCursorAnchorInfo().getComposingText().length());
}
@Test
public void inputConnection_textInputTypeNone() {
View testView = new View(RuntimeEnvironment.application);
DartExecutor dartExecutor = mock(DartExecutor.class);
TextInputChannel textInputChannel = new TextInputChannel(dartExecutor);
TextInputPlugin textInputPlugin =
new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class));
textInputPlugin.setTextInputClient(
0,
new TextInputChannel.Configuration(
false,
false,
true,
TextInputChannel.TextCapitalization.NONE,
new TextInputChannel.InputType(TextInputChannel.TextInputType.NONE, false, false),
null,
null,
null,
null));
InputConnection connection =
textInputPlugin.createInputConnection(
testView, mock(KeyboardManager.class), new EditorInfo());
assertEquals(connection, null);
}
@Test
public void showTextInput_textInputTypeNone() {
TestImm testImm =
Shadow.extract(
RuntimeEnvironment.application.getSystemService(Context.INPUT_METHOD_SERVICE));
View testView = new View(RuntimeEnvironment.application);
DartExecutor dartExecutor = mock(DartExecutor.class);
TextInputChannel textInputChannel = new TextInputChannel(dartExecutor);
TextInputPlugin textInputPlugin =
new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class));
textInputPlugin.setTextInputClient(
0,
new TextInputChannel.Configuration(
false,
false,
true,
TextInputChannel.TextCapitalization.NONE,
new TextInputChannel.InputType(TextInputChannel.TextInputType.NONE, false, false),
null,
null,
null,
null));
textInputPlugin.showTextInput(testView);
assertEquals(testImm.isSoftInputVisible(), false);
}
// -------- Start: Autofill Tests -------
@Test
public void autofill_onProvideVirtualViewStructure() {