-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dialog.js
42 lines (35 loc) · 977 Bytes
/
Dialog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* @provideModule Dialog
*/
'use strict';
import { Alert, AlertIOS, Platform, NativeModules } from 'react-native';
function alert(title, message, buttons) {
if (Platform.OS === 'ios') {
AlertIOS.alert(title, message, buttons);
} else {
Alert.alert(title, message, buttons);
}
}
function prompt(title, message, buttons) {
if (Platform.OS === 'ios') {
AlertIOS.prompt(title, message, buttons);
} else {
buttons = buttons.reverse().reduce((prevItem, currentItem, index) => {
let key = -index - 1;
prevItem[key] = currentItem;
return prevItem;
}, {});
let errorCallback = (buttonId, text) => {
consolo.log("error");
};
let successCallback = (buttonId, text) => {
buttonId = buttonId.toString();
buttons[buttonId].onPress(text);
};
NativeModules.PromptAndroid.show(title, message, buttons, errorCallback, successCallback);
}
}
module.exports = {
alert: alert,
prompt: prompt
};