Implement 'keyboardType' on native side (#104)

This commit is contained in:
Phecda Su 2019-01-14 10:37:55 +08:00 committed by Noitidart
parent 86341a5bfc
commit 8a4cbfdb5d
3 changed files with 97 additions and 48 deletions

View File

@ -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,

100
README.md
View File

@ -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
> }

View File

@ -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;