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 = {| type OptionsPrompt = {|
...OptionsCommon, ...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, defaultValue?: string,
placeholder?: string, placeholder?: string,
allowEmptyInput?: boolean, allowEmptyInput?: boolean,
@ -446,7 +446,7 @@ class DialogAndroid {
if (allowEmptyInput !== undefined) inputConfig.allowEmptyInput = allowEmptyInput; if (allowEmptyInput !== undefined) inputConfig.allowEmptyInput = allowEmptyInput;
if (minLength) inputConfig.minLength = minLength; if (minLength) inputConfig.minLength = minLength;
if (maxLength) inputConfig.maxLength = maxLength; 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 = { const nativeConfig = {
...DialogAndroid.defaults, ...DialogAndroid.defaults,

View File

@ -4,10 +4,10 @@
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. 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 ### Table of Contents
- [Installation](#installation) - [Installation](#installation)
- [Manual Linking](#manual-linking) - [Manual Linking](#manual-linking)
- [Usage](#usage) - [Usage](#usage)
- [API](#api) - [API](#api)
- [Properties](#properties) - [Properties](#properties)
- [`defaults`](#defaults) - [`defaults`](#defaults)
- [`actionDismiss`](#actiondismiss) - [`actionDismiss`](#actiondismiss)
@ -25,7 +25,7 @@ An Android only module for Material Design dialogs. This is a wrapper over [afol
- [`prompt`](#prompt) - [`prompt`](#prompt)
- [`showPicker`](#showpicker) - [`showPicker`](#showpicker)
- [`showProgress`](#showprogress) - [`showProgress`](#showprogress)
- [Types](#types) - [Types](#types)
- [Internal Types](#internal-types) - [Internal Types](#internal-types)
- [`type ActionType`](#type-actiontype) - [`type ActionType`](#type-actiontype)
- [`type ListItem`](#type-listitem) - [`type ListItem`](#type-listitem)
@ -37,7 +37,7 @@ An Android only module for Material Design dialogs. This is a wrapper over [afol
- [`type OptionsPicker`](#type-optionspicker) - [`type OptionsPicker`](#type-optionspicker)
- [`type OptionsPrompt`](#type-optionsprompt) - [`type OptionsPrompt`](#type-optionsprompt)
- [`type ProgressStyle`](#type-progressstyle) - [`type ProgressStyle`](#type-progressstyle)
- [Examples](#examples) - [Examples](#examples)
- [Progress Dialog](#progress-dialog) - [Progress Dialog](#progress-dialog)
- [Basic List](#basic-list) - [Basic List](#basic-list)
- [Radio List](#radio-list) - [Radio List](#radio-list)
@ -437,6 +437,20 @@ Shows a progress dialog. By default no buttons are shown, and hardware back butt
> { > {
> ...OptionsCommon, > ...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 > widgetColor?: ColorValue
> } > }

View File

@ -3,6 +3,7 @@ package com.aakashns.reactnativedialogs.modules;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.graphics.Color; import android.graphics.Color;
import android.text.Html; import android.text.Html;
import android.text.InputType;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.os.Build; import android.os.Build;
@ -367,9 +368,43 @@ public class DialogAndroid extends ReactContextBaseJavaModule {
// Check if empty input is allowed // Check if empty input is allowed
boolean allowEmptyInput = !input.hasKey("allowEmptyInput") || input.getBoolean("allowEmptyInput"); boolean allowEmptyInput = !input.hasKey("allowEmptyInput") || input.getBoolean("allowEmptyInput");
// TODO : Provide pre-selected input types in Javascript if (input.hasKey("keyboardType")) {
if (input.hasKey("type")) { switch (input.getString("keyboardType")) {
mBuilder.inputType(input.getInt("type")); 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; int minLength = input.hasKey("minLength") ? input.getInt("minLength") : 0;