forked from dominicstop/react-native-ios-context-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContextMenuViewTest08.tsx
75 lines (65 loc) · 1.88 KB
/
ContextMenuViewTest08.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
import * as React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import { ContextMenuView } from 'react-native-ios-context-menu';
import type { ContextMenuExampleProps } from './SharedExampleTypes';
import { ContextMenuCard } from '../components/ContextMenuCard';
export function ContextMenuViewTest08(props: ContextMenuExampleProps) {
const [counter, setCounter] = React.useState(0);
const menuRef = React.useRef<ContextMenuView>();
const intervalRef = React.useRef<NodeJS.Timer | undefined>();
React.useEffect(() => {
return () => {
if(!intervalRef.current) return;
clearInterval(intervalRef.current);
};
}, []);
return (
<ContextMenuView
style={props.style}
ref={menuRef}
previewConfig={{
previewType: 'CUSTOM',
backgroundColor: 'white'
}}
renderPreview={() => (
<View style={styles.previewContainer}>
<Text style={styles.previewCounterText}>
{`Will Dismiss in: ${3 - counter}`}
</Text>
</View>
)}
onMenuDidShow={() => {
let internalCounter = 0;
intervalRef.current = setInterval(() => {
if (internalCounter < 3){
setCounter(prevValue => (prevValue + 1));
internalCounter++;
} else if(internalCounter === 3) {
menuRef.current.dismissMenu();
};
}, 500);
}}
onMenuDidHide={() => {
clearInterval(intervalRef.current);
setCounter(0);
}}
>
<ContextMenuCard
index={props.index}
title={'ContextMenuViewTest08'}
subtitle={'dismiss menu'}
description={[
`Test for programmatically dismissing the menu.`
]}
/>
</ContextMenuView>
);
};
const styles = StyleSheet.create({
previewContainer: {
padding: 20,
},
previewCounterText: {
fontSize: 32,
},
});