MCPcopy Index your code
hub / github.com/callstack/react-native-paper / MenuExample

Function MenuExample

example/src/Examples/MenuExample.tsx:34–184  ·  view source on GitHub ↗
({ navigation }: Props)

Source from the content-addressed store, hash-verified

32const MORE_ICON = Platform.OS === 'ios' ? 'dots-horizontal' : 'dots-vertical';
33
34const MenuExample = ({ navigation }: Props) => {
35 const [visible, setVisible] = React.useState<MenuVisibility>({});
36 const [contextualMenuCoord, setContextualMenuCoor] =
37 React.useState<ContextualMenuCoord>({ x: 0, y: 0 });
38 const { isV3 } = useExampleTheme();
39
40 const _toggleMenu = (name: string) => () =>
41 setVisible({ ...visible, [name]: !visible[name] });
42
43 const _getVisible = (name: string) => !!visible[name];
44
45 const _handleLongPress = (event: GestureResponderEvent) => {
46 const { nativeEvent } = event;
47 setContextualMenuCoor({
48 x: nativeEvent.pageX,
49 y: nativeEvent.pageY,
50 });
51 setVisible({ menu3: true });
52 };
53
54 React.useLayoutEffect(() => {
55 navigation.setOptions({
56 headerShown: false,
57 });
58 }, [navigation]);
59
60 return (
61 <View style={styles.screen}>
62 <Appbar.Header elevated>
63 <Appbar.BackAction onPress={() => navigation.goBack()} />
64 <Appbar.Content title="Menu" />
65 <Menu
66 visible={_getVisible('menu1')}
67 onDismiss={_toggleMenu('menu1')}
68 anchor={
69 <Appbar.Action
70 icon={MORE_ICON}
71 onPress={_toggleMenu('menu1')}
72 {...(!isV3 && { color: 'white' })}
73 />
74 }
75 >
76 <Menu.Item onPress={() => {}} title="Undo" />
77 <Menu.Item onPress={() => {}} title="Redo" />
78 <Divider style={isV3 && styles.md3Divider} />
79 <Menu.Item onPress={() => {}} title="Cut" disabled />
80 <Menu.Item onPress={() => {}} title="Copy" disabled />
81 <Menu.Item onPress={() => {}} title="Paste" />
82 </Menu>
83 </Appbar.Header>
84 <ScreenWrapper
85 contentContainerStyle={styles.contentContainer}
86 style={styles.container}
87 >
88 <View>
89 <View style={styles.alignCenter}>
90 <Menu
91 visible={_getVisible('menu2')}

Callers

nothing calls this directly

Calls 3

useExampleThemeFunction · 0.90
_toggleMenuFunction · 0.85
_getVisibleFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…