BlueWallet/blue_modules/prompt.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-06-15 20:47:54 +02:00
import { Platform } from 'react-native';
import prompt from 'react-native-prompt-android';
2018-03-31 02:03:58 +02:00
2019-01-05 17:29:13 +01:00
module.exports = (title, text, isCancelable = true, type = 'secure-text') => {
const keyboardType = type === 'numeric' ? 'numeric' : 'default';
2020-06-15 20:47:54 +02:00
if (Platform.OS === 'ios' && type === 'numeric') {
// `react-native-prompt-android` on ios does not support numeric input
type = 'plain-text';
}
2018-09-18 08:48:53 +02:00
return new Promise((resolve, reject) => {
const buttons = isCancelable
? [
{
text: 'Cancel',
onPress: () => {
reject(Error('Cancel Pressed'));
},
style: 'cancel',
2018-09-18 08:48:53 +02:00
},
{
text: 'OK',
onPress: password => {
console.log('OK Pressed');
resolve(password);
},
2018-03-31 02:03:58 +02:00
},
]
: [
{
text: 'OK',
onPress: password => {
console.log('OK Pressed');
resolve(password);
},
},
];
prompt(title, text, buttons, {
2019-01-05 17:29:13 +01:00
type: type,
cancelable: isCancelable,
keyboardType,
});
2018-03-31 02:03:58 +02:00
});
};