Skip to content

Commit 32c4e5d

Browse files
committed
custom renderer example
1 parent 56bf1f0 commit 32c4e5d

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

examples/ExtensionExample.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Text } from 'react-native';
2+
import { Text, View } from 'react-native';
33
import Menu, {
44
MenuProvider,
55
MenuOptions,
@@ -25,6 +25,24 @@ const IconOption = ({iconName, text, value}) => (
2525
</MenuOption>
2626
)
2727

28+
const { computePosition } = renderers.ContextMenu;
29+
const roundedStyles = {
30+
backgroundColor: 'yellow',
31+
borderRadius: 30,
32+
}
33+
class RoundedContextMenu extends React.Component {
34+
render() {
35+
const { style, children, layouts, ...other } = this.props;
36+
const position = computePosition(layouts);
37+
return (
38+
<View {...other} style={[roundedStyles, style, position]}>
39+
{children}
40+
</View>
41+
);
42+
}
43+
}
44+
45+
2846
/* You can set default renderer for all menus just once in your application: */
2947
//Menu.setDefaultRenderer(renderers.NotAnimatedContextMenu);
3048

@@ -35,13 +53,20 @@ const ExtensionExample = () => (
3553
onSelect={value => alert(`Selected number: ${value}`)}
3654
renderer={renderers.NotAnimatedContextMenu}
3755
>
38-
<MenuTrigger text='Select option' />
56+
<MenuTrigger text='Select extension options' />
3957
<MenuOptions>
4058
<CheckedOption value={1} text='One' />
4159
<CheckedOption checked value={2} text='Two' />
4260
<IconOption value={3} iconName='rocket' text='Three' />
4361
</MenuOptions>
4462
</Menu>
63+
<Menu renderer={RoundedContextMenu}>
64+
<MenuTrigger text='Select rounded menu' />
65+
<MenuOptions>
66+
<MenuOption text="A"/>
67+
<MenuOption text="B"/>
68+
</MenuOptions>
69+
</Menu>
4570
</MenuProvider>
4671
);
4772

0 commit comments

Comments
 (0)