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

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

Merged
merged 1 commit into from
Nov 15, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,8 @@ public enum TextInputType {
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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ private static int inputTypeFromTextInputType(
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,40 @@ public void showTextInput_textInputTypeNone() {
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,20 @@ - (void)testKeyboardType {
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"];
Expand Down