import * as React from 'react'; import { Alert } from 'react-native'; import { Helpers } from 'react-native-ios-utilities'; import { ContextMenuView } from 'react-native-ios-context-menu'; import type { ExampleItemProps } from './SharedExampleTypes'; import { ContextMenuCard } from '../components/ContextMenuCard'; export function ContextMenuViewExample20(props: ExampleItemProps) { const [extraMenuItems, setExtraMenuItems] = React.useState([]); const [isLoading, setIsLoading] = React.useState(true); const [didLoadItems, setDidLoadItems] = React.useState(false); return ( { switch (nativeEvent.actionKey) { case 'clear_cache': // reset state... setExtraMenuItems([]); setIsLoading(false); setDidLoadItems(false); break; default: Alert.alert( 'onPressMenuItem Event', `actionKey: ${nativeEvent.actionKey} - actionTitle: ${nativeEvent.actionTitle}` ); }; }} // this event will fire when a deferred menu item is present... onMenuWillShow={async () => { if(didLoadItems) return; // for the purposes of this example, let's add a delay // before showing the loading indicator... // // this way, we can see the context menu updating and // showing the loading indicator. // // Ideally, `isLoading` should already be set to `true` // before the context menu is shown... await Helpers.timeout(750); setIsLoading(true); // loading... // dummy delay, wait for 2 second... await Helpers.timeout(2000); setDidLoadItems(true); // add extra menu items setExtraMenuItems([{ type: 'action', actionKey: 'action-02', actionTitle: 'Deferred Item 02', actionSubtitle: 'Deferred item...' }, { type: 'action', actionKey: 'action-03', actionTitle: 'Deferred Item 03', actionSubtitle: 'Deferred item...' }]); // hide the loading indicator setIsLoading(false); }} > ); };