-
Notifications
You must be signed in to change notification settings - Fork 35
/
ContextMenuViewTest06.tsx
84 lines (74 loc) · 2.25 KB
/
ContextMenuViewTest06.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import * as React from 'react';
import { ContextMenuView, type OnPressMenuItemEvent } from 'react-native-ios-context-menu';
import type { ExampleItemProps } from './SharedExampleTypes';
import { ContextMenuCard } from '../components/ContextMenuCard';
import { Alert } from 'react-native';
export function ContextMenuViewTest06(props: ExampleItemProps) {
const [itemCount, setItemCount] = React.useState(0);
const hasItems = (itemCount > 0);
const items = [...Array(itemCount).keys()];
const hanldeOnPressMenuItem: OnPressMenuItemEvent = ({nativeEvent}) => {
switch (nativeEvent.actionKey) {
case 'add-action':
setItemCount((prevValue) => (prevValue + 1));
break;
case 'delete-all':
setItemCount(0);
break;
default:
Alert.alert('onPressMenuItem', `actionKey: ${nativeEvent.actionKey}`);
break;
};
};
return (
<ContextMenuView
style={props.style}
menuConfig={{
menuTitle: 'ContextMenuViewTest06',
menuItems: [{
actionKey : 'add-action',
actionTitle: 'Add Action',
icon: {
type: 'IMAGE_SYSTEM',
imageValue: {
systemName: 'plus',
},
}
}, {
actionKey : 'delete-all',
actionTitle : 'Delete All',
menuAttributes: [hasItems? 'destructive' : 'disabled'],
icon: {
type: 'IMAGE_SYSTEM',
imageValue: {
systemName: 'trash',
},
}
}, {
menuTitle : 'submenu',
menuOptions: ['displayInline'],
menuItems : items.map(item => ({
actionKey : `item-key-${item}`,
actionTitle: `Action #${item}`,
icon: {
type: 'IMAGE_SYSTEM',
imageValue: {
systemName: (item % 2 === 0)? 'heart.fill' : 'heart',
},
}
})),
}],
}}
onPressMenuItem={hanldeOnPressMenuItem}
>
<ContextMenuCard
index={props.index}
title={'ContextMenuViewTest06'}
subtitle={'add menu action'}
description={[
`Test for programmatically adding a menu action`
]}
/>
</ContextMenuView>
);
};