forked from microsoft/react-native-code-push
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlertAdapter.js
More file actions
43 lines (35 loc) · 1.27 KB
/
AlertAdapter.js
File metadata and controls
43 lines (35 loc) · 1.27 KB
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
import React, { Platform } from "react-native";
let { Alert } = React;
if (Platform.OS === "android") {
function resolveNativeModule(name) {
const ReactNative = require("react-native");
try {
const turboModule =
ReactNative.TurboModuleRegistry && ReactNative.TurboModuleRegistry.get
? ReactNative.TurboModuleRegistry.get(name)
: null;
if (turboModule) return turboModule;
} catch (_e) {
// Ignore and fall back to legacy NativeModules.
}
return ReactNative.NativeModules ? ReactNative.NativeModules[name] : null;
}
const CodePushDialog = resolveNativeModule("CodePushDialog");
Alert = {
alert(title, message, buttons) {
if (buttons.length > 2) {
throw "Can only show 2 buttons for Android dialog.";
}
const button1Text = buttons[0] ? buttons[0].text : null,
button2Text = buttons[1] ? buttons[1].text : null;
if (!CodePushDialog) {
throw "CodePushDialog native module is not installed.";
}
CodePushDialog.showDialog(
title, message, button1Text, button2Text,
(buttonId) => { buttons[buttonId].onPress && buttons[buttonId].onPress(); },
(error) => { throw error; });
}
};
}
module.exports = { Alert };