Skip to content

Commit

Permalink
[TextInput] Add TextInputType.webSearch (#15762) (#56428)
Browse files Browse the repository at this point in the history
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 flutter/flutter#157562.

The flutter PR: flutter/flutter#158323
  • Loading branch information
stonemaster authored Nov 15, 2024
1 parent 1343116 commit 7a7df63
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
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

0 comments on commit 7a7df63

Please sign in to comment.