Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 214e17b

Browse files
committed
[TextInput] Add TextInputType.webSearch (#15762)
1 parent a2ada9a commit 214e17b

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,8 @@ public enum TextInputType {
717717
EMAIL_ADDRESS("TextInputType.emailAddress"),
718718
URL("TextInputType.url"),
719719
VISIBLE_PASSWORD("TextInputType.visiblePassword"),
720-
NONE("TextInputType.none");
720+
NONE("TextInputType.none"),
721+
WEB_SEARCH("TextInputType.webSearch");
721722

722723
static TextInputType fromValue(@NonNull String encodedName) throws NoSuchFieldException {
723724
for (TextInputType textInputType : TextInputType.values()) {

shell/platform/android/io/flutter/plugin/editing/TextInputPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ private static int inputTypeFromTextInputType(
252252
textType |= InputType.TYPE_TEXT_FLAG_MULTI_LINE;
253253
} else if (type.type == TextInputChannel.TextInputType.EMAIL_ADDRESS) {
254254
textType |= InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
255-
} else if (type.type == TextInputChannel.TextInputType.URL) {
255+
} else if (type.type == TextInputChannel.TextInputType.URL
256+
|| type.type == TextInputChannel.TextInputType.WEB_SEARCH) {
256257
textType |= InputType.TYPE_TEXT_VARIATION_URI;
257258
} else if (type.type == TextInputChannel.TextInputType.VISIBLE_PASSWORD) {
258259
textType |= InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;

shell/platform/android/test/io/flutter/plugin/editing/TextInputPluginTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,40 @@ public void showTextInput_textInputTypeNone() {
13561356
assertEquals(testImm.isSoftInputVisible(), false);
13571357
}
13581358

1359+
@Test
1360+
public void showTextInput_textInputTypeWebSearch() {
1361+
TestImm testImm = Shadow.extract(ctx.getSystemService(Context.INPUT_METHOD_SERVICE));
1362+
View testView = new View(ctx);
1363+
DartExecutor dartExecutor = mock(DartExecutor.class);
1364+
TextInputChannel textInputChannel = new TextInputChannel(dartExecutor);
1365+
ScribeChannel scribeChannel = new ScribeChannel(mock(DartExecutor.class));
1366+
TextInputPlugin textInputPlugin =
1367+
new TextInputPlugin(
1368+
testView, textInputChannel, scribeChannel, mock(PlatformViewsController.class));
1369+
textInputPlugin.setTextInputClient(
1370+
0,
1371+
new TextInputChannel.Configuration(
1372+
false,
1373+
false,
1374+
true,
1375+
true,
1376+
false,
1377+
TextInputChannel.TextCapitalization.NONE,
1378+
new TextInputChannel.InputType(TextInputChannel.TextInputType.WEB_SEARCH, false, false),
1379+
null,
1380+
null,
1381+
null,
1382+
null,
1383+
null));
1384+
1385+
EditorInfo editorInfo = new EditorInfo();
1386+
InputConnection connection =
1387+
textInputPlugin.createInputConnection(testView, mock(KeyboardManager.class), editorInfo);
1388+
1389+
assertEquals(
1390+
editorInfo.inputType, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
1391+
}
1392+
13591393
@Test
13601394
public void inputConnection_textInputTypeMultilineAndSuggestionsDisabled() {
13611395
// Regression test for https://github.com/flutter/flutter/issues/71679.

shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ static UIKeyboardType ToUIKeyboardType(NSDictionary* type) {
140140
if ([inputType isEqualToString:@"TextInputType.visiblePassword"]) {
141141
return UIKeyboardTypeASCIICapable;
142142
}
143+
if ([inputType isEqualToString:@"TextInputType.webSearch"]) {
144+
return UIKeyboardTypeWebSearch;
145+
}
143146
return UIKeyboardTypeDefault;
144147
}
145148

shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,20 @@ - (void)testKeyboardType {
307307
XCTAssertEqual(inputView.keyboardType, UIKeyboardTypeURL);
308308
}
309309

310+
- (void)testKeyboardTypeWebSearch {
311+
NSDictionary* config = self.mutableTemplateCopy;
312+
[config setValue:@{@"name" : @"TextInputType.webSearch"} forKey:@"inputType"];
313+
[self setClientId:123 configuration:config];
314+
315+
// Find all the FlutterTextInputViews we created.
316+
NSArray<FlutterTextInputView*>* inputFields = self.installedInputViews;
317+
318+
FlutterTextInputView* inputView = inputFields[0];
319+
320+
// Verify keyboardType is set to the value specified in config.
321+
XCTAssertEqual(inputView.keyboardType, UIKeyboardTypeWebSearch);
322+
}
323+
310324
- (void)testVisiblePasswordUseAlphanumeric {
311325
NSDictionary* config = self.mutableTemplateCopy;
312326
[config setValue:@{@"name" : @"TextInputType.visiblePassword"} forKey:@"inputType"];

0 commit comments

Comments
 (0)