MCPcopy
hub / github.com/callstack/react-native-paper / Menu

Function Menu

src/components/Menu/Menu.tsx:182–701  ·  view source on GitHub ↗
({
  visible,
  statusBarHeight,
  overlayAccessibilityLabel = 'Close menu',
  testID = 'menu',
  anchor,
  onDismiss,
  anchorPosition,
  contentStyle,
  style,
  elevation = DEFAULT_ELEVATION,
  mode = DEFAULT_MODE,
  children,
  theme: themeOverrides,
  keyboardShouldPersistTaps,
}: Props)

Source from the content-addressed store, hash-verified

180 */
181
182const Menu = ({
183 visible,
184 statusBarHeight,
185 overlayAccessibilityLabel = 'Close menu',
186 testID = 'menu',
187 anchor,
188 onDismiss,
189 anchorPosition,
190 contentStyle,
191 style,
192 elevation = DEFAULT_ELEVATION,
193 mode = DEFAULT_MODE,
194 children,
195 theme: themeOverrides,
196 keyboardShouldPersistTaps,
197}: Props) => {
198 const theme = useInternalTheme(themeOverrides);
199 const insets = useSafeAreaInsets();
200 const [rendered, setRendered] = React.useState(visible);
201 const [left, setLeft] = React.useState(0);
202 const [top, setTop] = React.useState(0);
203 const [menuLayout, setMenuLayout] = React.useState({ width: 0, height: 0 });
204 const [anchorLayout, setAnchorLayout] = React.useState({
205 width: 0,
206 height: 0,
207 });
208 const [windowLayout, setWindowLayout] = React.useState({
209 width: WINDOW_LAYOUT.width,
210 height: WINDOW_LAYOUT.height,
211 });
212
213 const opacityAnimationRef = React.useRef(new Animated.Value(0));
214 const scaleAnimationRef = React.useRef(new Animated.ValueXY({ x: 0, y: 0 }));
215 const keyboardHeightRef = React.useRef(0);
216 const prevVisible = React.useRef<boolean | null>(null);
217 const anchorRef = React.useRef<View | null>(null);
218 const menuRef = React.useRef<View | null>(null);
219 const prevRendered = React.useRef(false);
220
221 const keyboardDidShow = React.useCallback((e: RNKeyboardEvent) => {
222 const keyboardHeight = e.endCoordinates.height;
223 keyboardHeightRef.current = keyboardHeight;
224 }, []);
225
226 const keyboardDidHide = React.useCallback(() => {
227 keyboardHeightRef.current = 0;
228 }, []);
229
230 const keyboardDidShowListenerRef: React.RefObject<
231 EmitterSubscription | undefined
232 > = React.useRef(undefined);
233 const keyboardDidHideListenerRef: React.RefObject<
234 EmitterSubscription | undefined
235 > = React.useRef(undefined);
236
237 const backHandlerSubscriptionRef: React.RefObject<
238 NativeEventSubscription | undefined
239 > = React.useRef(undefined);

Callers

nothing calls this directly

Calls 9

useInternalThemeFunction · 0.90
addEventListenerFunction · 0.90
isBrowserFunction · 0.85
isCoordinateFunction · 0.85
measureMenuLayoutFunction · 0.85
focusFirstDOMNodeFunction · 0.85
removeEventListenerMethod · 0.80
removeMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…