-
Notifications
You must be signed in to change notification settings - Fork 35
/
ContextMenuViewTest05.tsx
163 lines (150 loc) · 4.52 KB
/
ContextMenuViewTest05.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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<Array<EventItem>>([]);
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 (
<ContextMenuView
style={props.style}
menuConfig={{
menuTitle: 'ContextMenuViewTest05',
menuItems: [{
actionKey : 'key-01',
actionTitle: 'Action #1',
icon: {
type: 'IMAGE_SYSTEM',
imageValue: {
systemName: 'folder',
},
}
}, {
actionKey : 'key-02' ,
actionTitle: 'Action #2',
icon: {
type: 'IMAGE_SYSTEM',
imageValue: {
systemName: 'dial.fill',
},
}
}, {
actionKey : 'key-03' ,
actionTitle: 'Action #3',
icon: {
type: 'IMAGE_SYSTEM',
imageValue: {
systemName: 'archivebox.fill',
},
}
}],
}}
onMenuWillShow ={() => 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}
>
<ContextMenuCard
index={props.index}
title={'ContextMenuViewTest05'}
subtitle={'context menu events'}
description={[
`Test for logging the menu events`
]}
>
{hasEvents? (
<ScrollView
contentContainerStyle={styles.eventContainer}
nestedScrollEnabled={true}
>
{recentEvents.map((item) => (
<View
key={`event-${item.timestamp}-${item.type}`}
style={styles.eventListItemContainer}
>
<Text style={styles.eventItemIndexText}>
{`${Helpers.pad(item.index, 3)}`}
</Text>
<Text style={styles.eventItemTimestampText}>
{`${item.timestamp}`}
</Text>
<Text style={styles.eventItemTypeText}>
{item.type}
</Text>
</View>
))}
</ScrollView>
):(
<View style={[styles.eventContainer, styles.eventContainerEmpty]}>
<Text style={styles.eventEmptyText}>
{'No Events To Show'}
</Text>
</View>
)}
</ContextMenuCard>
</ContextMenuView>
);
};
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)',
},
});