Vitaliy Vlasov dc4841f041
Add react-native-desktop-menu native module
Signed-off-by: Vitaliy Vlasov <siphiuel@gmail.com>
2018-12-01 02:03:06 +02:00

30 lines
582 B
JavaScript

'use strict';
type MenuItems = Array<{
text?: string,
onPress?: ?Function,
}>;
const NativeModules = require('react-native').NativeModules;
class DesktopMenu {
static show(
menuItems?: MenuItems
): void {
var itemNames = menuItems.map(i => i.text);
var itemMap = new Map();
for (let i = 0; i < menuItems.length; ++i) {
itemMap.set(menuItems[i].text, menuItems[i].onPress);
}
NativeModules.DesktopMenuManager.show(
itemNames,
(name) => {
(itemMap.get(name))();
}
);
}
}
module.exports = DesktopMenu;