diff --git a/DialogAndroid.js b/DialogAndroid.js index 2bfb4d1..02a6e8e 100644 --- a/DialogAndroid.js +++ b/DialogAndroid.js @@ -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, diff --git a/README.md b/README.md index ec519b5..a6f522f 100644 --- a/README.md +++ b/README.md @@ -4,49 +4,49 @@ An Android only module for Material Design dialogs. This is a wrapper over [afollestad/material-dialogs](https://github.com/afollestad/material-dialogs). This module is designed for Android only with no plans to support iOS. ### Table of Contents -- [Installation](#installation) - - [Manual Linking](#manual-linking) -- [Usage](#usage) -- [API](#api) - - [Properties](#properties) - - [`defaults`](#defaults) - - [`actionDismiss`](#actiondismiss) - - [`actionNegative`](#actionnegative) - - [`actionNeutral`](#actionneutral) - - [`actionPositive`](#actionpositive) - - [`listPlain`](#listplain) - - [`listRadio`](#listradio) - - [`listCheckbox`](#listcheckbox) - - [`progressHorizontal`](#progresshorizontal) - - [Methods](#methods) - - [`alert`](#alert) - - [`assignDefaults`](#assigndefaults) - - [`dismiss`](#dismiss) - - [`prompt`](#prompt) - - [`showPicker`](#showpicker) - - [`showProgress`](#showprogress) -- [Types](#types) - - [Internal Types](#internal-types) - - [`type ActionType`](#type-actiontype) - - [`type ListItem`](#type-listitem) - - [`type ListType`](#type-listtype) - - [`type OptionsAlert`](#type-optionsalert) - - [`type OptionsCheckbox`](#type-optionscheckbox) - - [`type OptionsCommon`](#type-optionscommon) - - [`type OptionsProgress`](#type-optionsprogress) - - [`type OptionsPicker`](#type-optionspicker) - - [`type OptionsPrompt`](#type-optionsprompt) - - [`type ProgressStyle`](#type-progressstyle) -- [Examples](#examples) - - [Progress Dialog](#progress-dialog) - - [Basic List](#basic-list) - - [Radio List](#radio-list) - - [Without auto-dismiss](#without-auto-dismiss) - - [Checklist](#checklist) - - [With clear list button](#with-clear-list-button) - - [Prompt](#prompt) - - [HTML](#html) - - [assignDefaults](#assigndefaults) + - [Installation](#installation) + - [Manual Linking](#manual-linking) + - [Usage](#usage) + - [API](#api) + - [Properties](#properties) + - [`defaults`](#defaults) + - [`actionDismiss`](#actiondismiss) + - [`actionNegative`](#actionnegative) + - [`actionNeutral`](#actionneutral) + - [`actionPositive`](#actionpositive) + - [`listPlain`](#listplain) + - [`listRadio`](#listradio) + - [`listCheckbox`](#listcheckbox) + - [`progressHorizontal`](#progresshorizontal) + - [Methods](#methods) + - [`alert`](#alert) + - [`assignDefaults`](#assigndefaults) + - [`dismiss`](#dismiss) + - [`prompt`](#prompt) + - [`showPicker`](#showpicker) + - [`showProgress`](#showprogress) + - [Types](#types) + - [Internal Types](#internal-types) + - [`type ActionType`](#type-actiontype) + - [`type ListItem`](#type-listitem) + - [`type ListType`](#type-listtype) + - [`type OptionsAlert`](#type-optionsalert) + - [`type OptionsCheckbox`](#type-optionscheckbox) + - [`type OptionsCommon`](#type-optionscommon) + - [`type OptionsProgress`](#type-optionsprogress) + - [`type OptionsPicker`](#type-optionspicker) + - [`type OptionsPrompt`](#type-optionsprompt) + - [`type ProgressStyle`](#type-progressstyle) + - [Examples](#examples) + - [Progress Dialog](#progress-dialog) + - [Basic List](#basic-list) + - [Radio List](#radio-list) + - [Without auto-dismiss](#without-auto-dismiss) + - [Checklist](#checklist) + - [With clear list button](#with-clear-list-button) + - [Prompt](#prompt) + - [HTML](#html) + - [assignDefaults](#assigndefaults) - [Contributors](#contributors) ### Installation @@ -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 > } diff --git a/android/src/main/java/com/aakashns/reactnativedialogs/modules/DialogAndroid.java b/android/src/main/java/com/aakashns/reactnativedialogs/modules/DialogAndroid.java index b2c209c..81f3cbc 100644 --- a/android/src/main/java/com/aakashns/reactnativedialogs/modules/DialogAndroid.java +++ b/android/src/main/java/com/aakashns/reactnativedialogs/modules/DialogAndroid.java @@ -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;