Skip to content

Commit 74433a5

Browse files
committed
⭐️ Example - Added: ContextMenuViewTest08
1 parent 5d6ef67 commit 74433a5

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

example/src/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { ContextMenuViewTest04 } from './components/ContextMenuView/ContextMenuV
2828
import { ContextMenuViewTest05 } from './components/ContextMenuView/ContextMenuViewTest05';
2929
import { ContextMenuViewTest06 } from './components/ContextMenuView/ContextMenuViewTest06';
3030
import { ContextMenuViewTest07 } from './components/ContextMenuView/ContextMenuViewTest07';
31+
import { ContextMenuViewTest08 } from './components/ContextMenuView/ContextMenuViewTest08';
3132

3233
import { ContextMenuButtonSimpleExample01 } from './components/ContextMenuButton/ContextMenuButtonSimpleExample01';
3334
import { ContextMenuButtonSimpleExample02 } from './components/ContextMenuButton/ContextMenuButtonSimpleExample02';
@@ -58,6 +59,7 @@ const contextMenuViewItems = [
5859
ContextMenuViewTest05,
5960
ContextMenuViewTest06,
6061
ContextMenuViewTest07,
62+
ContextMenuViewTest08,
6163
];
6264

6365
const contextMenuButtonItems = [
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import React, { useState, useRef } from 'react';
2+
import { StyleSheet, View, Text } from 'react-native';
3+
4+
import { ExampleContextMenuItem } from '../ExampleContextMenuItem';
5+
6+
7+
export class ContextMenuViewTest08 extends React.PureComponent {
8+
constructor(props){
9+
super(props);
10+
11+
this.timer = null;
12+
13+
this.state = {
14+
counter: 0,
15+
};
16+
};
17+
18+
componentWillUnmount() {
19+
this.resetTimer();
20+
};
21+
22+
startTimer = () => {
23+
this.timer = setInterval(() => {
24+
const { counter } = this.state;
25+
if (counter < 3){
26+
this.setState(prevState => ({
27+
counter: (prevState.counter + 1)
28+
}));
29+
30+
} else {
31+
const ref = this.contexMenuItemRef.getContextMenuRef()
32+
ref.dismissMenu();
33+
this.resetTimer();
34+
};
35+
}, 500);
36+
};
37+
38+
resetTimer = () => {
39+
if(this.timer){
40+
clearInterval(this.timer);
41+
this.setState({ counter: 0 });
42+
};
43+
};
44+
45+
render(){
46+
return (
47+
<ExampleContextMenuItem
48+
{...this.props}
49+
ref={r => this.contexMenuItemRef = r}
50+
title={'Test #8'}
51+
subtitle={'dismiss menu'}
52+
desc={`Test for programatically dismissing the menu.`}
53+
// `ContextMenuView` Props
54+
previewConfig={{
55+
previewType: 'CUSTOM',
56+
backgroundColor: 'white'
57+
}}
58+
renderPreview={() => (
59+
<View style={{ padding: 20 }}>
60+
<Text style={{fontSize: 32}}>
61+
{`Will Dismiss in: ${3 - this.state.counter}`}
62+
</Text>
63+
</View>
64+
)}
65+
onMenuDidShow={() => this.startTimer()}
66+
onMenuDidHide={() => this.resetTimer()}
67+
menuConfig={{
68+
menuTitle: 'ContextMenuViewTest08',
69+
}}
70+
/>
71+
);
72+
};
73+
};
74+
75+
const styles = StyleSheet.create({
76+
});

example/src/components/ExampleContextMenuItem.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ export class ExampleContextMenuItem extends React.Component {
5858
index : Proptypes.number,
5959
};
6060

61+
getContextMenuRef = () => {
62+
return this.contexMenuRef;
63+
};
64+
6165
render(){
6266
const { title, subtitle, desc, index, style, children, ...props } = this.props;
6367

6468
return(
65-
<ContextMenuView
69+
<ContextMenuView
70+
ref={r => this.contexMenuRef = r}
6671
style={[styles.rootContainer, style]}
6772
{...props}
6873
>

0 commit comments

Comments
 (0)