This repository has been archived by the owner on Aug 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.js
50 lines (43 loc) · 1.73 KB
/
index.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
43
44
45
46
47
48
49
50
/**
* @providesModule SimpleAlert
*/
'use strict';
import React from 'react';
import { AlertIOS, Platform, NativeModules } from 'react-native';
const SimpleAlertAndroid = NativeModules.SimpleAlertAndroid;
const Buttons = {
POSITIVE_BUTTON: "POSITIVE_BUTTON",
NEGATIVE_BUTTON: "NEGATIVE_BUTTON",
NEUTRAL_BUTTON: "NEUTRAL_BUTTON",
};
if (Platform.OS !== 'ios') {
Buttons = {
POSITIVE_BUTTON: SimpleAlertAndroid.POSITIVE_BUTTON,
NEGATIVE_BUTTON: SimpleAlertAndroid.NEGATIVE_BUTTON,
NEUTRAL_BUTTON: SimpleAlertAndroid.NEUTRAL_BUTTON,
};
}
const SimpleAlert = {
[Buttons.POSITIVE_BUTTON]: Buttons.POSITIVE_BUTTON,
[Buttons.NEGATIVE_BUTTON]: Buttons.NEGATIVE_BUTTON,
[Buttons.NEUTRAL_BUTTON]: Buttons.NEUTRAL_BUTTON,
alert(title, text, buttonConfig) {
let _buttonConfig = (buttonConfig||[{ type: SimpleAlert.POSITIVE_BUTTON, text: 'OK', }]);
if (Platform.OS === 'ios') {
for(let j=0; j<_buttonConfig.length; j++) {
if("type" && _buttonConfig[j]) delete _buttonConfig[j]['type'];
}
AlertIOS.alert.apply(AlertIOS, [title, text, _buttonConfig]);
} else {
let _masterCallback = (buttonType) => {
for(let j=0; j<_buttonConfig.length; j++) {
if("type" && _buttonConfig[j] && _buttonConfig[j].type === buttonType && ("onPress" in _buttonConfig[j] && typeof _buttonConfig[j].onPress == "function")) {
_buttonConfig[j].onPress.apply(null, [{type: buttonType}]);
}
}
};
SimpleAlertAndroid.alert((title||null), (text||null), _buttonConfig, _masterCallback);
}
}
};
module.exports = SimpleAlert;