2020-06-15 20:47:54 +02:00
|
|
|
import { Platform } from 'react-native';
|
2018-12-11 23:52:46 +01:00
|
|
|
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') => {
|
2020-10-20 10:20:52 +02:00
|
|
|
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) => {
|
2018-10-09 06:25:36 +02:00
|
|
|
const buttons = isCancelable
|
|
|
|
? [
|
|
|
|
{
|
|
|
|
text: 'Cancel',
|
|
|
|
onPress: () => {
|
|
|
|
reject(Error('Cancel Pressed'));
|
|
|
|
},
|
|
|
|
style: 'cancel',
|
2018-09-18 08:48:53 +02:00
|
|
|
},
|
2018-10-09 06:25:36 +02:00
|
|
|
{
|
|
|
|
text: 'OK',
|
|
|
|
onPress: password => {
|
2020-10-20 10:20:52 +02:00
|
|
|
console.log('OK Pressed');
|
2018-10-09 06:25:36 +02:00
|
|
|
resolve(password);
|
|
|
|
},
|
2018-03-31 02:03:58 +02:00
|
|
|
},
|
2018-10-09 06:25:36 +02:00
|
|
|
]
|
|
|
|
: [
|
|
|
|
{
|
|
|
|
text: 'OK',
|
|
|
|
onPress: password => {
|
2020-10-20 10:20:52 +02:00
|
|
|
console.log('OK Pressed');
|
2018-10-09 06:25:36 +02:00
|
|
|
resolve(password);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2018-12-11 23:52:46 +01:00
|
|
|
prompt(title, text, buttons, {
|
2019-01-05 17:29:13 +01:00
|
|
|
type: type,
|
2018-12-11 23:52:46 +01:00
|
|
|
cancelable: isCancelable,
|
2020-10-20 10:20:52 +02:00
|
|
|
keyboardType,
|
2018-12-11 23:52:46 +01:00
|
|
|
});
|
2018-03-31 02:03:58 +02:00
|
|
|
});
|
|
|
|
};
|