BlueWallet/blue_modules/showPopupMenu.android.ts
Marcos Rodriguez Vélez 32b36fbf9d
REF: Move file
2021-10-20 08:53:17 -04:00

33 lines
1.1 KiB
TypeScript

// @ts-ignore: Ignore
import type { Element } from 'react';
import { Text, TouchableNativeFeedback, TouchableWithoutFeedback, View, findNodeHandle, UIManager } from 'react-native';
type PopupMenuItem = { id?: any; label: string };
type OnPopupMenuItemSelect = (selectedPopupMenuItem: PopupMenuItem) => void;
type PopupAnchor = Element<typeof Text | typeof TouchableNativeFeedback | typeof TouchableWithoutFeedback | typeof View>;
type PopupMenuOptions = { onCancel?: () => void };
function showPopupMenu(
items: PopupMenuItem[],
onSelect: OnPopupMenuItemSelect,
anchor: PopupAnchor,
{ onCancel }: PopupMenuOptions = {},
): void {
UIManager.showPopupMenu(
// @ts-ignore: Ignore
findNodeHandle(anchor),
items.map(item => item.label),
function () {
if (onCancel) onCancel();
},
function (eventName: 'dismissed' | 'itemSelected', selectedIndex?: number) {
// @ts-ignore: Ignore
if (eventName === 'itemSelected') onSelect(items[selectedIndex]);
else onCancel && onCancel();
},
);
}
export type { PopupMenuItem, OnPopupMenuItemSelect, PopupMenuOptions };
export default showPopupMenu;