Repository navigation
[CP Staging] Revert "fix: Reports - More menu on expense RHP blocks primary and secondary button." #72070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CP Staging] Revert "fix: Reports - More menu on expense RHP blocks primary and secondary button." #72070
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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'; | ||
|
|
@@ -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[]) { | ||
|
|
@@ -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} | ||
|
|
@@ -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> | ||
|
|
@@ -477,5 +461,21 @@ function BasePopoverMenu({ | |
|
|
||
| PopoverMenu.displayName = 'PopoverMenu'; | ||
|
|
||
| export default PopoverMenu; | ||
| export default React.memo( | ||
| PopoverMenu, | ||
| (prevProps, nextProps) => | ||
| deepEqual(prevProps.menuItems, nextProps.menuItems) && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-5 (docs)Using 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}; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ PERF-5 (docs)
Using
deepEqualfor 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: