diff --git a/android/src/main/java/com/reactnativekeyboardcontroller/transformers/KeyboardType.kt b/android/src/main/java/com/reactnativekeyboardcontroller/transformers/KeyboardType.kt index 40cd99f94..3526e9203 100644 --- a/android/src/main/java/com/reactnativekeyboardcontroller/transformers/KeyboardType.kt +++ b/android/src/main/java/com/reactnativekeyboardcontroller/transformers/KeyboardType.kt @@ -11,30 +11,30 @@ fun getKeyboardTypeFromInputType(inputType: Int?): String { return "default" } + // Extract base input type class + val inputTypeClass = inputType and InputType.TYPE_MASK_CLASS + val inputTypeVariation = inputType and InputType.TYPE_MASK_VARIATION + + // Check for special input types return when { - // Check for numeric input types - inputType and InputType.TYPE_CLASS_NUMBER != 0 -> { + inputTypeVariation == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS -> "email-address" + inputTypeVariation == InputType.TYPE_TEXT_VARIATION_URI -> "url" + inputTypeVariation == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD -> "visible-password" + + // Check for specific input type classes + inputTypeClass == InputType.TYPE_CLASS_NUMBER -> when { - inputType and InputType.TYPE_NUMBER_FLAG_DECIMAL != 0 -> "decimal-pad" - inputType and INPUT_TYPE_KEYBOARD_NUMBERED != 0 -> "numeric" - else -> "number-pad" - } - } - // Check for email address type - inputType and InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS != 0 -> "email-address" + (inputType and InputType.TYPE_NUMBER_FLAG_DECIMAL) != 0 && + (inputType and InputType.TYPE_NUMBER_FLAG_SIGNED) == 0 -> "decimal-pad" - // Check for phone pad type - inputType and InputType.TYPE_CLASS_PHONE != 0 -> "phone-pad" + (inputType and InputType.TYPE_NUMBER_FLAG_SIGNED) != 0 -> "numeric" - // Check for URL type - inputType and InputType.TYPE_TEXT_VARIATION_URI != 0 -> "url" + else -> "number-pad" + } - // Check for visible password type - inputType and InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD != 0 -> "visible-password" + inputTypeClass == InputType.TYPE_CLASS_PHONE -> "phone-pad" + inputTypeClass == InputType.TYPE_CLASS_TEXT -> "default" - // Default case else -> "default" } } - - diff --git a/ios/events/KeyboardEventEmitterPayload.swift b/ios/events/KeyboardEventEmitterPayload.swift index afdb13e76..65f67568b 100644 --- a/ios/events/KeyboardEventEmitterPayload.swift +++ b/ios/events/KeyboardEventEmitterPayload.swift @@ -29,9 +29,7 @@ public class KeyboardTypeConverter: NSObject { } } -public func buildEventParams(_ height: Double, _ duration: Int, _ responder: UIResponder?) - -> [AnyHashable: Any] -{ +public func buildEventParams(_ height: Double, _ duration: Int, _ responder: UIResponder?) -> [AnyHashable: Any] { var data = [AnyHashable: Any]() data["height"] = height