Compare commits

..

1 Commits

Author SHA1 Message Date
钟加仁
bad2a3eba1 fix: adaptive react-native 0.60 2019-09-11 15:46:28 +08:00
4 changed files with 83 additions and 8 deletions

View File

@ -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
View 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);
};

View File

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

View File

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