From 75e49a0637eaa3bd3bb7e445648f084a42d9c8af Mon Sep 17 00:00:00 2001 From: Jens Panneel Date: Thu, 14 Jun 2018 13:53:58 -0700 Subject: [PATCH] Feature/add decimal pad to android (#19714) Summary: For a current use-case we need the a keyboard with characters 0-9 and a decimal point (or comma depending on language settings) This exists on iOS as UIKeyboardType "decimalPad" and this is what react-native maps to for both "numeric" and "decimal-pad". This also exists on Android as inputType "numberDecimal", but is currently not accessible through react-native. This PR maps the value "decimal-pad" of the keyboardType property of TextInput to the Android inputType "numberDecimal", effectively making "decimal-pad" cross platform without breaking anything. * https://facebook.github.io/react-native/docs/textinput.html#keyboardtype * https://developer.apple.com/documentation/uikit/uikeyboardtype * https://developer.android.com/reference/android/widget/TextView#attr_android:inputType There is this bug in some Samsung keyboards where both the - sign and decimal sign disappear when the keyboardType is set to "number" and both the "signed" and "decimal" flags are set. (Like is the case when using the react-native keyboardType prop "numeric".) https://androidforums.com/threads/numeric-soft-keyboard-missing-minus-sign-in-android-8-0-samsung-a5.1272628/ For developers that need decimal numbers but not negative ones, using "decimal-pad" will provide a workaround. I reproduced this on a Samsung A5 only, but maybe other phones have this exact issue. https://github.com/facebook/react-native/issues/12988 https://github.com/facebook/react-native/issues/12977 https://github.com/facebook/react-native/issues/17473 https://github.com/facebook/react-native/issues/17474 * Added testcase consistent with existing keyboardType tests * Also added testcase for the related, but missing number-pad This PR follows the same approach as the recently merged PR introducing "number-pad" https://github.com/facebook/react-native/pull/18350/commits/b638847a46491bd75e7ce7928c73f7cb78399195 Documentation PR: https://github.com/facebook/react-native-website/pull/405 [ANDROID] [ENHANCEMENT] [TextInput] - Added "decimal-pad" keyboard type Closes https://github.com/facebook/react-native/pull/19714 Differential Revision: D8429185 Pulled By: mdvacca fbshipit-source-id: 6b56da2088f2be427ebffa04c4e17c91ffb9f7d9 --- Libraries/Components/TextInput/TextInput.js | 4 ++-- .../react/views/textinput/ReactTextInputManager.java | 8 ++++++-- .../react/views/textinput/ReactTextInputPropertyTest.java | 8 ++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Libraries/Components/TextInput/TextInput.js b/Libraries/Components/TextInput/TextInput.js index c08033e8d..ef8d6a81f 100644 --- a/Libraries/Components/TextInput/TextInput.js +++ b/Libraries/Components/TextInput/TextInput.js @@ -86,12 +86,12 @@ export type KeyboardType = | 'numeric' | 'phone-pad' | 'number-pad' + | 'decimal-pad' // iOS-only | 'ascii-capable' | 'numbers-and-punctuation' | 'url' | 'name-phone-pad' - | 'decimal-pad' | 'twitter' | 'web-search' // Android-only @@ -388,6 +388,7 @@ const TextInput = createReactClass({ * - `default` * - `numeric` * - `number-pad` + * - `decimal-pad` * - `email-address` * - `phone-pad` * @@ -399,7 +400,6 @@ const TextInput = createReactClass({ * - `numbers-and-punctuation` * - `url` * - `name-phone-pad` - * - `decimal-pad` * - `twitter` * - `web-search` * diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java index 9311a74ab..3ee99b6c8 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java @@ -70,8 +70,9 @@ public class ReactTextInputManager extends BaseViewManager