Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ const CONST = {
POPOVER_DROPDOWN_WIDTH: 334,
POPOVER_DROPDOWN_MIN_HEIGHT: 0,
POPOVER_DROPDOWN_MAX_HEIGHT: 416,
POPOVER_MENU_MAX_HEIGHT: 496,
POPOVER_DATE_WIDTH: 338,
POPOVER_DATE_MAX_HEIGHT: 366,
POPOVER_DATE_MIN_HEIGHT: 322,
Expand Down
2 changes: 1 addition & 1 deletion src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ function MoneyReportHeader({
}}
buttonRef={buttonRef}
shouldAlwaysShowDropdownMenu
shouldPopoverUseScrollView={applicableSecondaryActions.length >= 5}
shouldPopoverUseScrollView={shouldDisplayNarrowVersion && applicableSecondaryActions.length >= 5}
customText={translate('common.more')}
options={applicableSecondaryActions}
isSplitButton={false}
Expand Down
60 changes: 30 additions & 30 deletions src/components/PopoverMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable react/jsx-props-no-spreading */
import {deepEqual} from 'fast-equals';
import type {ReactNode, RefObject} from 'react';
import React, {useCallback, useLayoutEffect, useMemo, useState} from 'react';
import {StyleSheet, View} from 'react-native';
Expand Down Expand Up @@ -171,7 +172,7 @@ const renderWithConditionalWrapper = (shouldUseScrollView: boolean, contentConta
return <ScrollView contentContainerStyle={contentContainerStyle}>{children}</ScrollView>;
}
// eslint-disable-next-line react/jsx-no-useless-fragment
return <View style={contentContainerStyle}>{children}</View>;
return <>{children}</>;
};

function getSelectedItemIndex(menuItems: PopoverMenuItem[]) {
Expand Down Expand Up @@ -408,32 +409,14 @@ function BasePopoverMenu({
}, [menuItems, setFocusedIndex]);

const menuContainerStyle = useMemo(() => {
const DEFAULT_MAX_HEIGHT_OFFSET = 250;
const SAFE_BOTTOM_SPACE = variables.h40;

if (!shouldEnableMaxHeight) {
return isSmallScreenWidth ? [] : [styles.createMenuContainer];
}

if (isSmallScreenWidth) {
return [{maxHeight: windowHeight - DEFAULT_MAX_HEIGHT_OFFSET}];
}

const isTopAnchored = anchorAlignment?.vertical === CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP;
const top = anchorPosition?.vertical;

// Reserve space for footer actions when expanding downward.
if (isTopAnchored && typeof top === 'number') {
const computed = windowHeight - Math.round(top) - SAFE_BOTTOM_SPACE;
const maxHeight = Math.min(CONST.POPOVER_MENU_MAX_HEIGHT, computed);
return [styles.createMenuContainer, {maxHeight}];
return shouldEnableMaxHeight ? {maxHeight: windowHeight - 250} : {};
}
return styles.createMenuContainer;
}, [isSmallScreenWidth, shouldEnableMaxHeight, windowHeight, styles.createMenuContainer]);

// Fallback for other anchor cases
return [styles.createMenuContainer, {maxHeight: windowHeight - DEFAULT_MAX_HEIGHT_OFFSET}];
}, [isSmallScreenWidth, shouldEnableMaxHeight, windowHeight, styles.createMenuContainer, anchorAlignment, anchorPosition]);
const {paddingTop, paddingBottom, paddingVertical, ...restScrollContainerStyle} = (StyleSheet.flatten([styles.pv4, scrollContainerStyle]) as ViewStyle) ?? {};

const {...restScrollContainerStyle} = (StyleSheet.flatten([styles.pv4, scrollContainerStyle]) as ViewStyle) ?? {};
return (
<PopoverWithMeasuredContent
anchorPosition={anchorPosition}
Expand Down Expand Up @@ -463,12 +446,13 @@ function BasePopoverMenu({
testID={testID}
>
<FocusTrapForModal active={isVisible}>
<View onLayout={onLayout}>
{renderWithConditionalWrapper(
shouldUseScrollView,
[restScrollContainerStyle, menuContainerStyle, containerStyles, {...(isWebOrDesktop ? styles.flex1 : styles.flexGrow1)}],
[renderHeaderText(), enteredSubMenuIndexes.length > 0 && renderBackButtonItem(), renderedMenuItems],
)}
<View
onLayout={onLayout}
style={[menuContainerStyle, containerStyles, {paddingTop, paddingBottom, paddingVertical, ...(isWebOrDesktop ? styles.flex1 : styles.flexGrow1)}]}
>
{renderHeaderText()}
{enteredSubMenuIndexes.length > 0 && renderBackButtonItem()}
{renderWithConditionalWrapper(shouldUseScrollView, restScrollContainerStyle, renderedMenuItems)}
</View>
</FocusTrapForModal>
</PopoverWithMeasuredContent>
Expand All @@ -477,5 +461,21 @@ function BasePopoverMenu({

PopoverMenu.displayName = 'PopoverMenu';

export default PopoverMenu;
export default React.memo(
PopoverMenu,
(prevProps, nextProps) =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-5 (docs)

Using deepEqual for React.memo comparisons creates performance overhead that often exceeds the re-render cost they aim to prevent. Deep equality checks recursively compare all nested properties.

Consider using shallow comparisons of specific relevant properties instead:

export default React.memo(
    PopoverMenu,
    (prevProps, nextProps) =>
        prevProps.menuItems === nextProps.menuItems &&
        prevProps.isVisible === nextProps.isVisible &&
        prevProps.anchorPosition === nextProps.anchorPosition &&
        // ... other primitive comparisons
);

deepEqual(prevProps.menuItems, nextProps.menuItems) &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-5 (docs)

Using deepEqual for comparing menuItems creates unnecessary performance overhead. Since menuItems is likely to be a new array reference on each render, this deep comparison will run on every update.

Consider using a reference equality check or memoizing the menuItems in the parent component:

prevProps.menuItems === nextProps.menuItems

prevProps.isVisible === nextProps.isVisible &&
deepEqual(prevProps.anchorPosition, nextProps.anchorPosition) &&
prevProps.anchorRef === nextProps.anchorRef &&
prevProps.headerText === nextProps.headerText &&
prevProps.fromSidebarMediumScreen === nextProps.fromSidebarMediumScreen &&
deepEqual(prevProps.anchorAlignment, nextProps.anchorAlignment) &&
prevProps.animationIn === nextProps.animationIn &&
prevProps.animationOut === nextProps.animationOut &&
prevProps.animationInTiming === nextProps.animationInTiming &&
prevProps.disableAnimation === nextProps.disableAnimation &&
prevProps.withoutOverlay === nextProps.withoutOverlay &&
prevProps.shouldSetModalVisibility === nextProps.shouldSetModalVisibility,
);
export type {PopoverMenuItem, PopoverMenuProps};