BlueWallet/blue_modules/showPopupMenu.android.ts

33 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-10-20 03:00:38 -04:00
// @ts-ignore: Ignore
2021-10-20 02:52:58 -04:00
import type { Element } from 'react';
2024-05-20 10:54:13 +01:00
import { findNodeHandle, Text, TouchableNativeFeedback, TouchableWithoutFeedback, UIManager, View } from 'react-native';
2021-10-20 02:52:58 -04:00
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(
2021-10-20 03:00:38 -04:00
// @ts-ignore: Ignore
2021-10-20 02:52:58 -04:00
findNodeHandle(anchor),
items.map(item => item.label),
2021-10-20 03:00:38 -04:00
function () {
2021-10-20 02:52:58 -04:00
if (onCancel) onCancel();
},
function (eventName: 'dismissed' | 'itemSelected', selectedIndex?: number) {
2021-10-20 03:00:38 -04:00
// @ts-ignore: Ignore
2021-10-20 02:52:58 -04:00
if (eventName === 'itemSelected') onSelect(items[selectedIndex]);
else onCancel && onCancel();
},
);
}
2024-05-20 10:54:13 +01:00
export type { OnPopupMenuItemSelect, PopupMenuItem, PopupMenuOptions };
2021-10-20 02:52:58 -04:00
export default showPopupMenu;