Support decimal information on the TextInputType (flutter/engine#19664)

* adding decimal inoutmode

* change intentation
This commit is contained in:
nturgut
2020-07-13 13:08:54 -07:00
committed by GitHub
parent de4f80fad2
commit 70de7f832c
3 changed files with 59 additions and 27 deletions

View File

@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of engine;
/// Various types of inputs used in text fields.
@@ -14,10 +13,10 @@ part of engine;
abstract class EngineInputType {
const EngineInputType();
static EngineInputType fromName(String name) {
static EngineInputType fromName(String name, {bool isDecimal = false}) {
switch (name) {
case 'TextInputType.number':
return number;
return isDecimal ? decimal : number;
case 'TextInputType.phone':
return phone;
case 'TextInputType.emailAddress':
@@ -38,6 +37,9 @@ abstract class EngineInputType {
/// Numeric input type.
static const NumberInputType number = NumberInputType();
/// Decimal input type.
static const DecimalInputType decimal = DecimalInputType();
/// Phone number input type.
static const PhoneInputType phone = PhoneInputType();
@@ -89,6 +91,8 @@ class TextInputType extends EngineInputType {
}
/// Numeric input type.
///
/// Input keyboard with only the digits 0–9.
class NumberInputType extends EngineInputType {
const NumberInputType();
@@ -96,6 +100,17 @@ class NumberInputType extends EngineInputType {
final String inputmodeAttribute = 'numeric';
}
/// Decimal input type.
///
/// Input keyboard with containing the digits 0–9 and a decimal separator.
/// Seperator can be `.`, `,` depending on the locale.
class DecimalInputType extends EngineInputType {
const DecimalInputType();
@override
final String inputmodeAttribute = 'decimal';
}
/// Phone number input type.
class PhoneInputType extends EngineInputType {
const PhoneInputType();

View File

@@ -435,7 +435,9 @@ class InputConfiguration {
InputConfiguration.fromFrameworkMessage(
Map<String, dynamic> flutterInputConfiguration)
: inputType = EngineInputType.fromName(
flutterInputConfiguration['inputType']['name']),
flutterInputConfiguration['inputType']['name'],
isDecimal:
flutterInputConfiguration['inputType']['decimal'] ?? false),
inputAction = flutterInputConfiguration['inputAction'],
obscureText = flutterInputConfiguration['obscureText'],
autocorrect = flutterInputConfiguration['autocorrect'],

View File

@@ -572,12 +572,14 @@ void main() {
/// the keyboard.
///
/// Returns the `clientId` used in the platform message.
int showKeyboard({String inputType, String inputAction}) {
int showKeyboard(
{String inputType, String inputAction, bool decimal = false}) {
final MethodCall setClient = MethodCall(
'TextInput.setClient',
<dynamic>[
++clientId,
createFlutterConfig(inputType, inputAction: inputAction),
createFlutterConfig(inputType,
inputAction: inputAction, decimal: decimal),
],
);
sendFrameworkMessage(codec.encodeMethodCall(setClient));
@@ -867,8 +869,7 @@ void main() {
expect(document.getElementsByTagName('form'), isEmpty);
});
test(
'No capitilization: setClient, setEditingState, show', () {
test('No capitilization: setClient, setEditingState, show', () {
// Create a configuration with an AutofillGroup of four text fields.
final Map<String, dynamic> capitilizeWordsConfig = createFlutterConfig(
'text',
@@ -908,8 +909,7 @@ void main() {
hideKeyboard();
});
test(
'All characters capitilization: setClient, setEditingState, show', () {
test('All characters capitilization: setClient, setEditingState, show', () {
// Create a configuration with an AutofillGroup of four text fields.
final Map<String, dynamic> capitilizeWordsConfig = createFlutterConfig(
'text',
@@ -1356,6 +1356,12 @@ void main() {
showKeyboard(inputType: 'number');
expect(getEditingInputMode(), 'numeric');
showKeyboard(inputType: 'number', decimal: false);
expect(getEditingInputMode(), 'numeric');
showKeyboard(inputType: 'number', decimal: true);
expect(getEditingInputMode(), 'decimal');
showKeyboard(inputType: 'phone');
expect(getEditingInputMode(), 'tel');
@@ -1369,29 +1375,36 @@ void main() {
});
test('sets correct input type in iOS', () {
debugOperatingSystemOverride = OperatingSystem.iOs;
debugBrowserEngineOverride = BrowserEngine.webkit;
// Test on ios-safari only.
if (browserEngine == BrowserEngine.webkit &&
operatingSystem == OperatingSystem.iOs) {
/// During initialization [HybridTextEditing] will pick the correct
/// text editing strategy for [OperatingSystem.iOs].
textEditing = HybridTextEditing();
/// During initialization [HybridTextEditing] will pick the correct
/// text editing strategy for [OperatingSystem.iOs].
textEditing = HybridTextEditing();
showKeyboard(inputType: 'text');
expect(getEditingInputMode(), 'text');
showKeyboard(inputType: 'text');
expect(getEditingInputMode(), 'text');
showKeyboard(inputType: 'number');
expect(getEditingInputMode(), 'numeric');
showKeyboard(inputType: 'number');
expect(getEditingInputMode(), 'numeric');
showKeyboard(inputType: 'number', decimal: false);
expect(getEditingInputMode(), 'numeric');
showKeyboard(inputType: 'phone');
expect(getEditingInputMode(), 'tel');
showKeyboard(inputType: 'number', decimal: true);
expect(getEditingInputMode(), 'decimal');
showKeyboard(inputType: 'emailAddress');
expect(getEditingInputMode(), 'email');
showKeyboard(inputType: 'phone');
expect(getEditingInputMode(), 'tel');
showKeyboard(inputType: 'url');
expect(getEditingInputMode(), 'url');
showKeyboard(inputType: 'emailAddress');
expect(getEditingInputMode(), 'email');
hideKeyboard();
showKeyboard(inputType: 'url');
expect(getEditingInputMode(), 'url');
hideKeyboard();
}
});
test('sends the correct input action as a platform message', () {
@@ -1798,10 +1811,12 @@ Map<String, dynamic> createFlutterConfig(
String inputAction,
String autofillHint,
List<String> autofillHintsForFields,
bool decimal = false,
}) {
return <String, dynamic>{
'inputType': <String, String>{
'inputType': <String, dynamic>{
'name': 'TextInputType.$inputType',
if (decimal) 'decimal': true,
},
'obscureText': obscureText,
'autocorrect': autocorrect,