menu icon indicating copy to clipboard operation
menu copied to clipboard

Adding imperative call API

Open vmourot opened this issue 3 years ago • 1 comments

It would be nice to allow to trigger the menu without require a component. Ex :

import { showMenu } from '@react-native-menu/menu';

const props = { title: 'My title' };
const actions = [
  {
    id: 'add',
    /*...*/
  }
];
const onPressAction = ({nativeEvent}) => { console.warn(JSON.stringify(nativeEvent)); }

/* this call : */
showMenu(props, actions, onPressAction);

vmourot avatar Apr 20 '21 16:04 vmourot

Hi, in principle it's not possible with current native components, since they need to be attached to "some element/view". In theory it's possible to achieve that on iOS with UIMenuController, but on Android it requires changes in an Activity (onCreateContextMenu and probably onContextMenuItemSelected methods) which because of nature of RN on Android is impossible to do within the 3rd party library context (every user would need to do an extra step after library installation - and I guess that it wouldn't be one line addition)

mateusz1913 avatar Apr 20 '21 17:04 mateusz1913