11/* eslint-disable react/jsx-props-no-spreading */
2+ import { deepEqual } from 'fast-equals' ;
23import type { ReactNode , RefObject } from 'react' ;
34import React , { useCallback , useLayoutEffect , useMemo , useState } from 'react' ;
45import { StyleSheet , View } from 'react-native' ;
@@ -171,7 +172,7 @@ const renderWithConditionalWrapper = (shouldUseScrollView: boolean, contentConta
171172 return < ScrollView contentContainerStyle = { contentContainerStyle } > { children } </ ScrollView > ;
172173 }
173174 // eslint-disable-next-line react/jsx-no-useless-fragment
174- return < View style = { contentContainerStyle } > { children } </ View > ;
175+ return < > { children } </ > ;
175176} ;
176177
177178function getSelectedItemIndex ( menuItems : PopoverMenuItem [ ] ) {
@@ -408,32 +409,14 @@ function BasePopoverMenu({
408409 } , [ menuItems , setFocusedIndex ] ) ;
409410
410411 const menuContainerStyle = useMemo ( ( ) => {
411- const DEFAULT_MAX_HEIGHT_OFFSET = 250 ;
412- const SAFE_BOTTOM_SPACE = variables . h40 ;
413-
414- if ( ! shouldEnableMaxHeight ) {
415- return isSmallScreenWidth ? [ ] : [ styles . createMenuContainer ] ;
416- }
417-
418412 if ( isSmallScreenWidth ) {
419- return [ { maxHeight : windowHeight - DEFAULT_MAX_HEIGHT_OFFSET } ] ;
420- }
421-
422- const isTopAnchored = anchorAlignment ?. vertical === CONST . MODAL . ANCHOR_ORIGIN_VERTICAL . TOP ;
423- const top = anchorPosition ?. vertical ;
424-
425- // Reserve space for footer actions when expanding downward.
426- if ( isTopAnchored && typeof top === 'number' ) {
427- const computed = windowHeight - Math . round ( top ) - SAFE_BOTTOM_SPACE ;
428- const maxHeight = Math . min ( CONST . POPOVER_MENU_MAX_HEIGHT , computed ) ;
429- return [ styles . createMenuContainer , { maxHeight} ] ;
413+ return shouldEnableMaxHeight ? { maxHeight : windowHeight - 250 } : { } ;
430414 }
415+ return styles . createMenuContainer ;
416+ } , [ isSmallScreenWidth , shouldEnableMaxHeight , windowHeight , styles . createMenuContainer ] ) ;
431417
432- // Fallback for other anchor cases
433- return [ styles . createMenuContainer , { maxHeight : windowHeight - DEFAULT_MAX_HEIGHT_OFFSET } ] ;
434- } , [ isSmallScreenWidth , shouldEnableMaxHeight , windowHeight , styles . createMenuContainer , anchorAlignment , anchorPosition ] ) ;
418+ const { paddingTop, paddingBottom, paddingVertical, ...restScrollContainerStyle } = ( StyleSheet . flatten ( [ styles . pv4 , scrollContainerStyle ] ) as ViewStyle ) ?? { } ;
435419
436- const { ...restScrollContainerStyle } = ( StyleSheet . flatten ( [ styles . pv4 , scrollContainerStyle ] ) as ViewStyle ) ?? { } ;
437420 return (
438421 < PopoverWithMeasuredContent
439422 anchorPosition = { anchorPosition }
@@ -463,12 +446,13 @@ function BasePopoverMenu({
463446 testID = { testID }
464447 >
465448 < FocusTrapForModal active = { isVisible } >
466- < View onLayout = { onLayout } >
467- { renderWithConditionalWrapper (
468- shouldUseScrollView ,
469- [ restScrollContainerStyle , menuContainerStyle , containerStyles , { ...( isWebOrDesktop ? styles . flex1 : styles . flexGrow1 ) } ] ,
470- [ renderHeaderText ( ) , enteredSubMenuIndexes . length > 0 && renderBackButtonItem ( ) , renderedMenuItems ] ,
471- ) }
449+ < View
450+ onLayout = { onLayout }
451+ style = { [ menuContainerStyle , containerStyles , { paddingTop, paddingBottom, paddingVertical, ...( isWebOrDesktop ? styles . flex1 : styles . flexGrow1 ) } ] }
452+ >
453+ { renderHeaderText ( ) }
454+ { enteredSubMenuIndexes . length > 0 && renderBackButtonItem ( ) }
455+ { renderWithConditionalWrapper ( shouldUseScrollView , restScrollContainerStyle , renderedMenuItems ) }
472456 </ View >
473457 </ FocusTrapForModal >
474458 </ PopoverWithMeasuredContent >
@@ -477,5 +461,21 @@ function BasePopoverMenu({
477461
478462PopoverMenu . displayName = 'PopoverMenu' ;
479463
480- export default PopoverMenu ;
464+ export default React . memo (
465+ PopoverMenu ,
466+ ( prevProps , nextProps ) =>
467+ deepEqual ( prevProps . menuItems , nextProps . menuItems ) &&
468+ prevProps . isVisible === nextProps . isVisible &&
469+ deepEqual ( prevProps . anchorPosition , nextProps . anchorPosition ) &&
470+ prevProps . anchorRef === nextProps . anchorRef &&
471+ prevProps . headerText === nextProps . headerText &&
472+ prevProps . fromSidebarMediumScreen === nextProps . fromSidebarMediumScreen &&
473+ deepEqual ( prevProps . anchorAlignment , nextProps . anchorAlignment ) &&
474+ prevProps . animationIn === nextProps . animationIn &&
475+ prevProps . animationOut === nextProps . animationOut &&
476+ prevProps . animationInTiming === nextProps . animationInTiming &&
477+ prevProps . disableAnimation === nextProps . disableAnimation &&
478+ prevProps . withoutOverlay === nextProps . withoutOverlay &&
479+ prevProps . shouldSetModalVisibility === nextProps . shouldSetModalVisibility ,
480+ ) ;
481481export type { PopoverMenuItem , PopoverMenuProps } ;
0 commit comments