[web] - Fix inputmode on Android Firefox (flutter/engine#46901)

The wrong keyboard type shows when users specify the phone input type in the framework. 

This is happening because:

* We usually set `inputmode` for mobile text editing strategies.
* We only use Android's text editing strategy for Blink browser engines (not firefox), so we fall through to the Firefox text editing strategy which I believe should only be used for desktop firefox.
* So we're ending up in a case where Android + Firefox doesn't set the inputmode and it pops open the default alphanumeric keyboard

Fixes https://github.com/flutter/flutter/issues/136351
This commit is contained in:
Hassan Toor
2024-02-08 14:10:48 -06:00
committed by GitHub
parent 4eae677520
commit 650f4b9728
2 changed files with 42 additions and 7 deletions

View File

@@ -1940,19 +1940,19 @@ class TextInputSetClient extends TextInputCommand {
/// Creates the text editing strategy used in non-a11y mode.
DefaultTextEditingStrategy createDefaultTextEditingStrategy(HybridTextEditing textEditing) {
DefaultTextEditingStrategy strategy;
if (browserEngine == BrowserEngine.webkit &&
operatingSystem == OperatingSystem.iOs) {
if(operatingSystem == OperatingSystem.iOs) {
strategy = IOSTextEditingStrategy(textEditing);
} else if (browserEngine == BrowserEngine.webkit) {
strategy = SafariDesktopTextEditingStrategy(textEditing);
} else if (browserEngine == BrowserEngine.blink &&
operatingSystem == OperatingSystem.android) {
} else if(operatingSystem == OperatingSystem.android) {
strategy = AndroidTextEditingStrategy(textEditing);
} else if (browserEngine == BrowserEngine.firefox) {
} else if(browserEngine == BrowserEngine.webkit) {
strategy = SafariDesktopTextEditingStrategy(textEditing);
} else if(browserEngine == BrowserEngine.firefox) {
strategy = FirefoxTextEditingStrategy(textEditing);
} else {
strategy = GloballyPositionedTextEditingStrategy(textEditing);
}
return strategy;
}

View File

@@ -2245,6 +2245,41 @@ Future<void> testMain() async {
hideKeyboard();
});
test('sets correct input type for Firefox on Android', () {
debugOperatingSystemOverride = OperatingSystem.android;
debugBrowserEngineOverride = BrowserEngine.firefox;
/// During initialization [HybridTextEditing] will pick the correct
/// text editing strategy for [OperatingSystem.android].
textEditing = HybridTextEditing();
showKeyboard(inputType: 'text');
expect(getEditingInputMode(), null);
showKeyboard(inputType: 'number');
expect(getEditingInputMode(), 'numeric');
showKeyboard(inputType: 'number');
expect(getEditingInputMode(), 'numeric');
showKeyboard(inputType: 'number', decimal: true);
expect(getEditingInputMode(), 'decimal');
showKeyboard(inputType: 'phone');
expect(getEditingInputMode(), 'tel');
showKeyboard(inputType: 'emailAddress');
expect(getEditingInputMode(), 'email');
showKeyboard(inputType: 'url');
expect(getEditingInputMode(), 'url');
showKeyboard(inputType: 'none');
expect(getEditingInputMode(), 'none');
hideKeyboard();
});
test('prevent mouse events on Android', () {
// Regression test for https://github.com/flutter/flutter/issues/124483.
debugOperatingSystemOverride = OperatingSystem.android;