mirror of
https://github.com/status-im/react-native-dialogs.git
synced 2025-03-01 00:30:28 +00:00
Implement 'keyboardType' on native side (#104)
This commit is contained in:
parent
86341a5bfc
commit
8a4cbfdb5d
@ -172,7 +172,7 @@ type ProgressStyle = typeof DialogAndroid.progressHorizontal;
|
||||
|
||||
type OptionsPrompt = {|
|
||||
...OptionsCommon,
|
||||
keyboardType?: 'numeric' | 'numbers-and-punctuation' | 'numeric-password' | 'email-address' | 'password' | 'phone-pad' | 'decimal-pad',
|
||||
keyboardType?: 'numeric' | 'number-pad' | 'decimal-pad' | 'numeric-password' | 'email-address' | 'password' | 'phone-pad' | 'url',
|
||||
defaultValue?: string,
|
||||
placeholder?: string,
|
||||
allowEmptyInput?: boolean,
|
||||
@ -446,7 +446,7 @@ class DialogAndroid {
|
||||
if (allowEmptyInput !== undefined) inputConfig.allowEmptyInput = allowEmptyInput;
|
||||
if (minLength) inputConfig.minLength = minLength;
|
||||
if (maxLength) inputConfig.maxLength = maxLength;
|
||||
// if (keyboardType) inputConfig.keyboardType = keyboardType; // TODO: support this on native side - https://github.com/aakashns/react-native-dialogs/pull/55
|
||||
if (keyboardType) inputConfig.keyboardType = keyboardType;
|
||||
|
||||
const nativeConfig = {
|
||||
...DialogAndroid.defaults,
|
||||
|
14
README.md
14
README.md
@ -437,6 +437,20 @@ Shows a progress dialog. By default no buttons are shown, and hardware back butt
|
||||
|
||||
> {
|
||||
> ...OptionsCommon,
|
||||
> keyboardType?:
|
||||
> | 'numeric'
|
||||
> | 'number-pad'
|
||||
> | 'numeric-password'
|
||||
> | 'decimal-pad'
|
||||
> | 'email-address'
|
||||
> | 'password'
|
||||
> | 'phone-pad'
|
||||
> | 'url',
|
||||
> defaultValue?: string,
|
||||
> placeholder?: string,
|
||||
> allowEmptyInput?: boolean,
|
||||
> minLength?: number,
|
||||
> maxLength?: number,
|
||||
> widgetColor?: ColorValue
|
||||
> }
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.aakashns.reactnativedialogs.modules;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Color;
|
||||
import android.text.Html;
|
||||
import android.text.InputType;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.os.Build;
|
||||
@ -367,9 +368,43 @@ public class DialogAndroid extends ReactContextBaseJavaModule {
|
||||
// Check if empty input is allowed
|
||||
boolean allowEmptyInput = !input.hasKey("allowEmptyInput") || input.getBoolean("allowEmptyInput");
|
||||
|
||||
// TODO : Provide pre-selected input types in Javascript
|
||||
if (input.hasKey("type")) {
|
||||
mBuilder.inputType(input.getInt("type"));
|
||||
if (input.hasKey("keyboardType")) {
|
||||
switch (input.getString("keyboardType")) {
|
||||
case "phone-pad":
|
||||
mBuilder.inputType(InputType.TYPE_CLASS_PHONE);
|
||||
break;
|
||||
|
||||
case "number-pad":
|
||||
mBuilder.inputType(InputType.TYPE_CLASS_NUMBER);
|
||||
break;
|
||||
|
||||
case "decimal-pad":
|
||||
mBuilder.inputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
||||
break;
|
||||
|
||||
case "numeric":
|
||||
mBuilder.inputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED);
|
||||
break;
|
||||
|
||||
case "numeric-password":
|
||||
mBuilder.inputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
|
||||
break;
|
||||
|
||||
case "email-address":
|
||||
mBuilder.inputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
|
||||
break;
|
||||
|
||||
case "password":
|
||||
mBuilder.inputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||
break;
|
||||
|
||||
case "url":
|
||||
mBuilder.inputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_URI);
|
||||
break;
|
||||
|
||||
default:
|
||||
mBuilder.inputType(InputType.TYPE_CLASS_TEXT);
|
||||
}
|
||||
}
|
||||
|
||||
int minLength = input.hasKey("minLength") ? input.getInt("minLength") : 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user