Compare commits
1 Commits
master
...
feature/up
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bad2a3eba1 |
@ -3,7 +3,75 @@ import {
|
||||
} from 'react-native';
|
||||
const PromptAndroid = NativeModules.PromptAndroid;
|
||||
|
||||
export default function prompt(title, message, callbackOrButtons, options) {
|
||||
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 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 {
|
||||
const defaultButtons = [
|
||||
{
|
||||
text: 'Cancel',
|
||||
@ -35,7 +103,7 @@ export default function prompt(title, message, callbackOrButtons, options) {
|
||||
}
|
||||
// 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.slice(0, 3) : [{text: 'OK'}];
|
||||
const validButtons: Buttons = buttons ? buttons.slice(0, 3) : [{text: 'OK'}];
|
||||
const buttonPositive = validButtons.pop();
|
||||
const buttonNegative = validButtons.pop();
|
||||
const buttonNeutral = validButtons.pop();
|
||||
|
||||
12
index.ios.js
Normal file
12
index.ios.js
Normal file
@ -0,0 +1,12 @@
|
||||
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, options.keyboardType);
|
||||
};
|
||||
5
index.js
5
index.js
@ -1,5 +0,0 @@
|
||||
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": "1.0.0",
|
||||
"version": "0.3.5",
|
||||
"description": "Polyfill for Alert.prompt on Android",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user