[TextInput] Add TextInputType.webSearch (#15762) (flutter/engine#56428)

This PR adds the engine part to add `TextInputType.webSearch` that allows to show a keyboard with ready access to a "." key on iOS. On Android this is re-mapped to `url` which shows the same behaviour as `webSearch` on iOS. This fixes issue https://github.com/flutter/flutter/issues/157562.

The flutter PR: https://github.com/flutter/flutter/pull/158323
This commit is contained in:
André Stein
2024-11-15 22:51:21 +01:00
committed by GitHub
parent d27125f326
commit 5ae19147fa
5 changed files with 55 additions and 2 deletions

View File

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

View File

@@ -252,7 +252,8 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch
textType |= InputType.TYPE_TEXT_FLAG_MULTI_LINE;
} else if (type.type == TextInputChannel.TextInputType.EMAIL_ADDRESS) {
textType |= InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
} else if (type.type == TextInputChannel.TextInputType.URL) {
} else if (type.type == TextInputChannel.TextInputType.URL
|| type.type == TextInputChannel.TextInputType.WEB_SEARCH) {
textType |= InputType.TYPE_TEXT_VARIATION_URI;
} else if (type.type == TextInputChannel.TextInputType.VISIBLE_PASSWORD) {
textType |= InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;

View File

@@ -1356,6 +1356,40 @@ public class TextInputPluginTest {
assertEquals(testImm.isSoftInputVisible(), false);
}
@Test
public void showTextInput_textInputTypeWebSearch() {
TestImm testImm = Shadow.extract(ctx.getSystemService(Context.INPUT_METHOD_SERVICE));
View testView = new View(ctx);
DartExecutor dartExecutor = mock(DartExecutor.class);
TextInputChannel textInputChannel = new TextInputChannel(dartExecutor);
ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class));
TextInputPlugin textInputPlugin =
new TextInputPlugin(
testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class));
textInputPlugin.setTextInputClient(
0,
new TextInputChannel.Configuration(
false,
false,
true,
true,
false,
TextInputChannel.TextCapitalization.NONE,
new TextInputChannel.InputType(TextInputChannel.TextInputType.WEB_SEARCH, false, false),
null,
null,
null,
null,
null));
EditorInfo editorInfo = new EditorInfo();
InputConnection connection =
textInputPlugin.createInputConnection(testView, mock(KeyboardManager.class), editorInfo);
assertEquals(
editorInfo.inputType, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
}
@Test
public void inputConnection_textInputTypeMultilineAndSuggestionsDisabled() {
// Regression test for https://github.com/flutter/flutter/issues/71679.

View File

@@ -140,6 +140,9 @@ static UIKeyboardType ToUIKeyboardType(NSDictionary* type) {
if ([inputType isEqualToString:@"TextInputType.visiblePassword"]) {
return UIKeyboardTypeASCIICapable;
}
if ([inputType isEqualToString:@"TextInputType.webSearch"]) {
return UIKeyboardTypeWebSearch;
}
return UIKeyboardTypeDefault;
}

View File

@@ -307,6 +307,20 @@ FLUTTER_ASSERT_ARC
XCTAssertEqual(inputView.keyboardType, UIKeyboardTypeURL);
}
- (void)testKeyboardTypeWebSearch {
NSDictionary* config = self.mutableTemplateCopy;
[config setValue:@{@"name" : @"TextInputType.webSearch"} forKey:@"inputType"];
[self setClientId:123 configuration:config];
// Find all the FlutterTextInputViews we created.
NSArray<FlutterTextInputView*>* inputFields = self.installedInputViews;
FlutterTextInputView* inputView = inputFields[0];
// Verify keyboardType is set to the value specified in config.
XCTAssertEqual(inputView.keyboardType, UIKeyboardTypeWebSearch);
}
- (void)testVisiblePasswordUseAlphanumeric {
NSDictionary* config = self.mutableTemplateCopy;
[config setValue:@{@"name" : @"TextInputType.visiblePassword"} forKey:@"inputType"];