UNPKG

5.16 kBTypeScriptView Raw
1import * as React from 'react';
2import { StyleProp, Animated, LayoutRectangle, ViewStyle } from 'react-native';
3import type { $Omit } from '../../types';
4import MenuItem from './MenuItem';
5declare type Props = {
6 /**
7 * Whether the Menu is currently visible.
8 */
9 visible: boolean;
10 /**
11 * The anchor to open the menu from. In most cases, it will be a button that opens the menu.
12 */
13 anchor: React.ReactNode | {
14 x: number;
15 y: number;
16 };
17 /**
18 * Extra margin to add at the top of the menu to account for translucent status bar on Android.
19 * If you are using Expo, we assume translucent status bar and set a height for status bar automatically.
20 * Pass `0` or a custom value to and customize it.
21 * This is automatically handled on iOS.
22 */
23 statusBarHeight?: number;
24 /**
25 * Callback called when Menu is dismissed. The `visible` prop needs to be updated when this is called.
26 */
27 onDismiss: () => void;
28 /**
29 * Accessibility label for the overlay. This is read by the screen reader when the user taps outside the menu.
30 */
31 overlayAccessibilityLabel?: string;
32 /**
33 * Content of the `Menu`.
34 */
35 children: React.ReactNode;
36 /**
37 * Style of menu's inner content.
38 */
39 contentStyle?: StyleProp<ViewStyle>;
40 style?: StyleProp<ViewStyle>;
41 /**
42 * @optional
43 */
44 theme: ReactNativePaper.Theme;
45};
46declare type Layout = $Omit<$Omit<LayoutRectangle, 'x'>, 'y'>;
47declare type State = {
48 rendered: boolean;
49 top: number;
50 left: number;
51 menuLayout: Layout;
52 anchorLayout: Layout;
53 opacityAnimation: Animated.Value;
54 scaleAnimation: Animated.ValueXY;
55};
56/**
57 * Menus display a list of choices on temporary elevated surfaces. Their placement varies based on the element that opens them.
58 *
59 * <div class="screenshots">
60 * <img class="medium" src="screenshots/menu-1.png" />
61 * <img class="medium" src="screenshots/menu-2.png" />
62 * </div>
63 *
64 * ## Usage
65 * ```js
66 * import * as React from 'react';
67 * import { View } from 'react-native';
68 * import { Button, Menu, Divider, Provider } from 'react-native-paper';
69 *
70 * const MyComponent = () => {
71 * const [visible, setVisible] = React.useState(false);
72 *
73 * const openMenu = () => setVisible(true);
74 *
75 * const closeMenu = () => setVisible(false);
76 *
77 * return (
78 * <Provider>
79 * <View
80 * style={{
81 * paddingTop: 50,
82 * flexDirection: 'row',
83 * justifyContent: 'center',
84 * }}>
85 * <Menu
86 * visible={visible}
87 * onDismiss={closeMenu}
88 * anchor={<Button onPress={openMenu}>Show menu</Button>}>
89 * <Menu.Item onPress={() => {}} title="Item 1" />
90 * <Menu.Item onPress={() => {}} title="Item 2" />
91 * <Divider />
92 * <Menu.Item onPress={() => {}} title="Item 3" />
93 * </Menu>
94 * </View>
95 * </Provider>
96 * );
97 * };
98 *
99 * export default MyComponent;
100 * ```
101 */
102declare class Menu extends React.Component<Props, State> {
103 static Item: typeof MenuItem;
104 static defaultProps: {
105 statusBarHeight: any;
106 overlayAccessibilityLabel: string;
107 };
108 static getDerivedStateFromProps(nextProps: Props, prevState: State): {
109 rendered: boolean;
110 } | null;
111 state: {
112 rendered: boolean;
113 top: number;
114 left: number;
115 menuLayout: {
116 width: number;
117 height: number;
118 };
119 anchorLayout: {
120 width: number;
121 height: number;
122 };
123 opacityAnimation: Animated.Value;
124 scaleAnimation: Animated.ValueXY;
125 };
126 componentDidUpdate(prevProps: Props): void;
127 componentWillUnmount(): void;
128 private anchor?;
129 private menu?;
130 private isCoordinate;
131 private measureMenuLayout;
132 private measureAnchorLayout;
133 private updateVisibility;
134 private isBrowser;
135 private focusFirstDOMNode;
136 private handleDismiss;
137 private handleKeypress;
138 private attachListeners;
139 private removeListeners;
140 private show;
141 private hide;
142 render(): JSX.Element;
143}
144declare const _default: (React.ComponentClass<Pick<Props, "style" | "anchor" | "children" | "visible" | "contentStyle" | "statusBarHeight" | "onDismiss" | "overlayAccessibilityLabel"> & {
145 theme?: import("@callstack/react-theme-provider").$DeepPartial<ReactNativePaper.Theme> | undefined;
146}, any> & import("@callstack/react-theme-provider/typings/hoist-non-react-statics").NonReactStatics<(React.ComponentClass<Props, any> & typeof Menu) | (React.FunctionComponent<Props> & typeof Menu), {}>) | (React.FunctionComponent<Pick<Props, "style" | "anchor" | "children" | "visible" | "contentStyle" | "statusBarHeight" | "onDismiss" | "overlayAccessibilityLabel"> & {
147 theme?: import("@callstack/react-theme-provider").$DeepPartial<ReactNativePaper.Theme> | undefined;
148}> & import("@callstack/react-theme-provider/typings/hoist-non-react-statics").NonReactStatics<(React.ComponentClass<Props, any> & typeof Menu) | (React.FunctionComponent<Props> & typeof Menu), {}>);
149export default _default;