import * as React from 'react'; import { StyleSheet, View, Text, ScrollView } 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'; type EventItem = { timestamp: string; type: string; index: number; }; export function ContextMenuViewTest05(props: ExampleItemProps) { const [events, setEvents] = React.useState>([]); const hasEvents = (events.length > 0); const recentEvents = events.reverse().slice(-15); const handleEvent = (eventName: string) => { const date = new Date(); const h = Helpers.pad(date.getHours ()); const m = Helpers.pad(date.getMinutes()); const s = Helpers.pad(date.getSeconds()); const ms = Helpers.pad(date.getMilliseconds(), 3); setEvents((prevValue) => ([ ...prevValue, { timestamp: `${h}:${m}:${s}.${ms}`, type: eventName, index: prevValue.length }])); }; return ( handleEvent('onMenuWillShow' )} onMenuWillHide ={() => handleEvent('onMenuWillHide' )} onMenuWillCancel ={() => handleEvent('onMenuWillCancel' )} onMenuDidShow ={() => handleEvent('onMenuDidShow' )} onMenuDidHide ={() => handleEvent('onMenuDidHide' )} onMenuDidCancel ={() => handleEvent('onMenuDidCancel' )} onPressMenuItem ={() => handleEvent('onPressMenuItem' )} onPressMenuPreview={() => handleEvent('onPressMenuPreview')} shouldWaitForMenuToHideBeforeFiringOnPressMenuItem={false} > {hasEvents? ( {recentEvents.map((item) => ( {`${Helpers.pad(item.index, 3)}`} {`${item.timestamp}`} {item.type} ))} ):( {'No Events To Show'} )} ); }; const styles = StyleSheet.create({ eventContainer: { marginTop: 15, height: 150, backgroundColor: 'rgba(255,255,255,0.3)', borderRadius: 10, paddingHorizontal: 12, paddingVertical: 7, }, eventContainerEmpty: { alignItems: 'center', justifyContent: 'center', }, eventEmptyText: { fontWeight: '600', fontSize: 16, color: 'rgba(0,0,0,0.4)', }, eventListItemContainer: { flexDirection: 'row', }, eventItemIndexText: { fontVariant: ['tabular-nums'], fontWeight: '600', color: 'rgba(0,0,0,0.3)', }, eventItemTimestampText: { fontVariant: ['tabular-nums'], marginLeft: 12, fontWeight: '300', color: 'rgba(0,0,0,0.75)', }, eventItemTypeText: { marginLeft: 12, fontWeight: '400', color: 'rgba(0,0,0,0.9)', }, });