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: 1 addition & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ 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 @@ -1165,7 +1165,7 @@ function MoneyReportHeader({
}}
buttonRef={buttonRef}
shouldAlwaysShowDropdownMenu
shouldPopoverUseScrollView={shouldDisplayNarrowVersion && applicableSecondaryActions.length >= 5}
shouldPopoverUseScrollView={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,5 +1,4 @@
/* 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 @@ -172,7 +171,7 @@ const renderWithConditionalWrapper = (shouldUseScrollView: boolean, contentConta
return <ScrollView contentContainerStyle={contentContainerStyle}>{children}</ScrollView>;
}
// eslint-disable-next-line react/jsx-no-useless-fragment
return <>{children}</>;
return <View style={contentContainerStyle}>{children}</View>;
};

function getSelectedItemIndex(menuItems: PopoverMenuItem[]) {
Expand Down Expand Up @@ -409,14 +408,32 @@ 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 shouldEnableMaxHeight ? {maxHeight: windowHeight - 250} : {};
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 styles.createMenuContainer;
}, [isSmallScreenWidth, shouldEnableMaxHeight, windowHeight, styles.createMenuContainer]);

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

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

PopoverMenu.displayName = 'PopoverMenu';

export default React.memo(
PopoverMenu,
(prevProps, nextProps) =>
deepEqual(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 default PopoverMenu;
export type {PopoverMenuItem, PopoverMenuProps};