Compare commits
28 Commits
fix/ValidF
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed168d66fe | ||
|
|
2073b07f64 | ||
|
|
957e99cd4e | ||
|
|
7eae9e24cd | ||
|
|
12ec414163 | ||
|
|
b9b9b93acf | ||
|
|
83d23015c9 | ||
|
|
50b7f288c2 | ||
|
|
27f6c528d3 | ||
|
|
36a3725f82 | ||
|
|
cafe32c074 | ||
|
|
645b4023ab | ||
|
|
65624e69f8 | ||
|
|
b30c8395f0 | ||
|
|
9354a8e8f8 | ||
|
|
946dd01f87 | ||
|
|
9c1ffa4605 | ||
|
|
a928f1c12e | ||
|
|
18a79c92d3 | ||
|
|
1af614c921 | ||
|
|
9e40f3a994 | ||
|
|
8e34686146 | ||
|
|
7c5cca5861 | ||
|
|
951ce90ec1 | ||
|
|
b53293aa08 | ||
|
|
68da243e8c | ||
|
|
5be7159c6c | ||
|
|
8822b42cb2 |
@ -1,2 +1 @@
|
||||
node_modules/
|
||||
Example/
|
||||
|
||||
@ -49,6 +49,7 @@ prompt(
|
||||
type | Text input type: `'numeric', 'secure-text', 'phone-pad', 'email-address'` | String | 'default'
|
||||
cancelable | | Boolean |
|
||||
defaultValue | Default input value | String | ''
|
||||
keyboardType | The keyboard type of first text field(if exists). One of `'default'`, `'email-address'`, `'numeric'`, `'phone-pad'`, `'ascii-capable'`, `'numbers-and-punctuation'`, `'url'`, `'number-pad'`, `'name-phone-pad'`, `'decimal-pad'`, `'twitter'` or `'web-search'`. | String | 'default'
|
||||
placeholder | | String | ''
|
||||
|
||||
|
||||
|
||||
@ -1,24 +1,19 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.2.3'
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
def DEFAULT_COMPILE_SDK_VERSION = 27
|
||||
def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3"
|
||||
def DEFAULT_MIN_SDK_VERSION = 16
|
||||
def DEFAULT_TARGET_SDK_VERSION = 27
|
||||
|
||||
android {
|
||||
compileSdkVersion 23
|
||||
buildToolsVersion "23.0.1"
|
||||
compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
|
||||
buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 23
|
||||
minSdkVersion rootProject.hasProperty('minSdkVersion') ? rootProject.minSdkVersion : DEFAULT_MIN_SDK_VERSION
|
||||
targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
versionName "1.1"
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
@ -35,7 +30,8 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "com.android.support:appcompat-v7:23.0.1"
|
||||
compile 'com.facebook.react:react-native:+'
|
||||
compile fileTree( dir: "libs", includes: ['*.jar'] )
|
||||
implementation 'androidx.appcompat:appcompat:1.0.0'
|
||||
implementation 'com.facebook.react:react-native:+'
|
||||
implementation fileTree( dir: "libs", includes: ['*.jar'] )
|
||||
}
|
||||
|
||||
|
||||
@ -5,12 +5,13 @@ import android.app.DialogFragment;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.InputType;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class RNPromptFragment extends DialogFragment implements DialogInterface.OnClickListener {
|
||||
@ -155,7 +156,9 @@ public class RNPromptFragment extends DialogFragment implements DialogInterface.
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
Dialog dialog = this.createDialog(getActivity(), getArguments());
|
||||
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||
if (mInputText.requestFocus()) {
|
||||
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||
}
|
||||
return dialog;
|
||||
}
|
||||
|
||||
|
||||
@ -183,7 +183,7 @@ public class RNPromptModule extends ReactContextBaseJavaModule implements Lifecy
|
||||
PromptFragmentListener actionListener =
|
||||
actionCallback != null ? new PromptFragmentListener(actionCallback) : null;
|
||||
|
||||
final RNPromptFragment promptFragment = new RNPromptFragment(actionListener, arguments);
|
||||
final RNPromptFragment promptFragment = new RNPromptFragment();
|
||||
promptFragment.setListener(actionListener);
|
||||
promptFragment.setArguments(arguments);
|
||||
|
||||
|
||||
@ -4,5 +4,5 @@
|
||||
android:layout_height="match_parent"
|
||||
android:textCursorDrawable="@drawable/edit_text_cursor"
|
||||
style="@style/ShimoEditTextStyle"
|
||||
android:theme="@style/ShimoEditTextStyle">
|
||||
</EditText>
|
||||
android:imeOptions="actionDone"
|
||||
android:theme="@style/ShimoEditTextStyle"/>
|
||||
|
||||
@ -4,7 +4,8 @@
|
||||
<item name="colorAccent">@color/prompt_color</item>
|
||||
</style>
|
||||
|
||||
<style name="ShimoEditTextStyle" parent="Widget.AppCompat.EditText">
|
||||
<style name="ShimoEditTextStyle">
|
||||
<item name="android:textColor">@color/prompt_color</item>
|
||||
<item name="colorControlNormal">@color/prompt_color</item>
|
||||
<item name="colorControlActivated">@color/prompt_color</item>
|
||||
<item name="colorControlHighlight">@color/prompt_color</item>
|
||||
|
||||
@ -3,88 +3,26 @@ import {
|
||||
} from 'react-native';
|
||||
const PromptAndroid = NativeModules.PromptAndroid;
|
||||
|
||||
export type PromptType = $Enum<{
|
||||
/**
|
||||
* Default alert with no inputs
|
||||
*/
|
||||
'default': string,
|
||||
/**
|
||||
* Plain text input alert
|
||||
*/
|
||||
'plain-text': string,
|
||||
/**
|
||||
* Secure text input alert
|
||||
*/
|
||||
'secure-text': string,
|
||||
/**
|
||||
* Numeric input alert
|
||||
*/
|
||||
'numeric': string,
|
||||
/**
|
||||
* Email address input alert
|
||||
*/
|
||||
'email-address': string,
|
||||
/**
|
||||
* Phone pad input alert
|
||||
*/
|
||||
'phone-pad': string,
|
||||
}>;
|
||||
export default function prompt(title, message, callbackOrButtons, options) {
|
||||
const defaultButtons = [
|
||||
{
|
||||
text: 'Cancel',
|
||||
},
|
||||
{
|
||||
text: 'OK',
|
||||
onPress: callbackOrButtons
|
||||
}
|
||||
];
|
||||
|
||||
export type PromptStyle = $Enum<{
|
||||
/**
|
||||
* Default alert dialog style
|
||||
*/
|
||||
'default': string,
|
||||
/**
|
||||
* Shimo alert dialog style
|
||||
*/
|
||||
'shimo': string,
|
||||
}>;
|
||||
|
||||
type Options = {
|
||||
cancelable?: ?boolean;
|
||||
type?: ?PromptType;
|
||||
defaultValue?: ?String;
|
||||
placeholder?: ?String;
|
||||
style?: ?PromptStyle;
|
||||
};
|
||||
|
||||
/**
|
||||
* Array or buttons
|
||||
* @typedef {Array} ButtonsArray
|
||||
* @property {string=} text Button label
|
||||
* @property {Function=} onPress Callback function when button pressed
|
||||
*/
|
||||
type ButtonsArray = Array<{
|
||||
/**
|
||||
* Button label
|
||||
*/
|
||||
text?: string,
|
||||
/**
|
||||
* Callback function when button pressed
|
||||
*/
|
||||
onPress?: ?Function,
|
||||
}>;
|
||||
|
||||
export default function prompt(
|
||||
title: ?string,
|
||||
message?: ?string,
|
||||
callbackOrButtons?: ?((text: string) => void) | ButtonsArray,
|
||||
options?: Options
|
||||
): void {
|
||||
let buttons = callbackOrButtons;
|
||||
let buttons = typeof callbackOrButtons === 'function'
|
||||
? defaultButtons
|
||||
: callbackOrButtons;
|
||||
|
||||
let config = {
|
||||
title: title || '',
|
||||
message: message || '',
|
||||
};
|
||||
|
||||
if (typeof callbackOrButtons === 'function') {
|
||||
buttons.push({
|
||||
text: 'OK',
|
||||
onPress: callbackOrButtons
|
||||
});
|
||||
}
|
||||
|
||||
if (options) {
|
||||
config = {
|
||||
...config,
|
||||
@ -97,7 +35,7 @@ export default function prompt(
|
||||
}
|
||||
// At most three buttons (neutral, negative, positive). Ignore rest.
|
||||
// The text 'OK' should be probably localized. iOS Alert does that in native.
|
||||
const validButtons: Buttons = buttons ? buttons.slice(0, 3) : [{text: 'OK'}];
|
||||
const validButtons = buttons ? buttons.slice(0, 3) : [{text: 'OK'}];
|
||||
const buttonPositive = validButtons.pop();
|
||||
const buttonNegative = validButtons.pop();
|
||||
const buttonNeutral = validButtons.pop();
|
||||
|
||||
59
index.d.ts
vendored
Normal file
59
index.d.ts
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
// Type definitions for react-native-prompt-android 0.3.1
|
||||
// Project: https://github.com/shimohq/react-native-prompt-android
|
||||
// Definitions by: Krystof Celba <https://github.com/krystofcelba>
|
||||
// TypeScript Version: 2.6.1
|
||||
|
||||
type PromptButton = {
|
||||
text?: string;
|
||||
onPress?: (message: string) => void;
|
||||
|
||||
/** @platform ios */
|
||||
style?: 'default' | 'cancel' | 'destructive';
|
||||
};
|
||||
|
||||
type PromptType = 'default' | 'plain-text' | 'secure-text';
|
||||
type PromptTypeIOS = 'login-password';
|
||||
type PromptTypeAndroid = 'numeric' | 'email-address' | 'phone-pad';
|
||||
|
||||
type PromptStyleAndroid = 'default' | 'shimo';
|
||||
|
||||
export interface PromptOptions {
|
||||
/**
|
||||
* * Cross platform:
|
||||
*
|
||||
* - `'default'`
|
||||
* - `'plain-text'`
|
||||
* - `'secure-text'`
|
||||
*
|
||||
* * iOS only:
|
||||
*
|
||||
* - `'login-password'`
|
||||
*
|
||||
* * Android only:
|
||||
*
|
||||
* - `'numeric'`
|
||||
* - `'email-address'`
|
||||
* - `'phone-pad'`
|
||||
*/
|
||||
type?: PromptType | PromptTypeIOS | PromptTypeAndroid;
|
||||
|
||||
defaultValue?: string;
|
||||
|
||||
/** @platform android */
|
||||
placeholder?: string;
|
||||
|
||||
/** @platform android */
|
||||
cancelable?: boolean;
|
||||
|
||||
/** @platform android */
|
||||
style?: PromptStyleAndroid;
|
||||
}
|
||||
|
||||
declare function prompt(
|
||||
title?: string,
|
||||
message?: string,
|
||||
callbackOrButtons?: ((value: string) => void) | Array<PromptButton>,
|
||||
options?: PromptOptions,
|
||||
): void;
|
||||
|
||||
export default prompt;
|
||||
12
index.ios.js
12
index.ios.js
@ -1,12 +0,0 @@
|
||||
import {
|
||||
AlertIOS
|
||||
} from 'react-native';
|
||||
|
||||
export default function prompt(
|
||||
title: ?string,
|
||||
message?: ?string,
|
||||
callbackOrButtons?: ?((text: string) => void) | Object,
|
||||
options?: Object
|
||||
): void {
|
||||
AlertIOS.prompt(title, message, callbackOrButtons, options.type, options.defaultValue);
|
||||
};
|
||||
5
index.js
Normal file
5
index.js
Normal file
@ -0,0 +1,5 @@
|
||||
import { Alert } from 'react-native';
|
||||
|
||||
export default function prompt(title, message, callbackOrButtons, options) {
|
||||
Alert.prompt(title, message, callbackOrButtons, options.type, options.defaultValue, options.keyboardType);
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-prompt-android",
|
||||
"version": "0.3.0",
|
||||
"version": "1.0.0",
|
||||
"description": "Polyfill for Alert.prompt on Android",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user