Skip to content

Commit

Permalink
Merge pull request #24013 from Nikhil-Vats/23140_fix_popover_menu_pos…
Browse files Browse the repository at this point in the history
…ition

Fix popover menu position for three dots menu and settlement button
  • Loading branch information
Julesssss authored Aug 7, 2023
2 parents 80df2ed + 4d0df0c commit 474a8f1
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ const CONST = {
CENTER: 'center',
RIGHT: 'right',
},
POPOVER_MENU_PADDING: 8,
},
TIMING: {
CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION: 'calc_most_recent_last_modified_action',
Expand Down
22 changes: 16 additions & 6 deletions src/components/ButtonWithDropdownMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,23 @@ const propTypes = {
iconDescription: PropTypes.string,
}),
).isRequired,

/** The anchor alignment of the popover menu */
anchorAlignment: PropTypes.shape({
horizontal: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL)),
vertical: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_VERTICAL)),
}),
};

const defaultProps = {
isLoading: false,
isDisabled: false,
menuHeaderText: '',
style: [],
anchorAlignment: {
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, // we assume that popover menu opens below the button, anchor is at TOP
},
};

function ButtonWithDropdownMenu(props) {
Expand All @@ -66,10 +76,13 @@ function ButtonWithDropdownMenu(props) {
caretButton.current.measureInWindow((x, y, w, h) => {
setPopoverAnchorPosition({
horizontal: x + w,
vertical: y + h,
vertical:
props.anchorAlignment.vertical === CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP
? y + h + CONST.MODAL.POPOVER_MENU_PADDING // if vertical anchorAlignment is TOP, menu will open below the button and we need to add the height of button and padding
: y - CONST.MODAL.POPOVER_MENU_PADDING, // if it is BOTTOM, menu will open above the button so NO need to add height but DO subtract padding
});
});
}, [windowWidth, windowHeight, isMenuVisible]);
}, [windowWidth, windowHeight, isMenuVisible, props.anchorAlignment.vertical]);

return (
<View>
Expand Down Expand Up @@ -119,10 +132,7 @@ function ButtonWithDropdownMenu(props) {
anchorPosition={popoverAnchorPosition}
anchorRef={caretButton}
withoutOverlay
anchorAlignment={{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
}}
anchorAlignment={props.anchorAlignment}
headerText={props.menuHeaderText}
menuItems={_.map(props.options, (item, index) => ({
...item,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import _ from 'underscore';
import PropTypes from 'prop-types';
import {ThreeDotsMenuItemPropTypes} from '../ThreeDotsMenu';
import CONST from '../../CONST';
import iouReportPropTypes from '../../pages/iouReportPropTypes';
import participantPropTypes from '../participantPropTypes';

Expand Down Expand Up @@ -50,12 +48,6 @@ const propTypes = {
left: PropTypes.number,
}),

/** The anchor alignment of the menu */
threeDotsAnchorAlignment: PropTypes.shape({
horizontal: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL)),
vertical: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_VERTICAL)),
}),

/** Whether we should show a close button */
shouldShowCloseButton: PropTypes.bool,

Expand Down
5 changes: 0 additions & 5 deletions src/components/HeaderWithBackButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ function HeaderWithBackButton({
subtitle = '',
title = '',
titleColor = undefined,
threeDotsAnchorAlignment = {
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP,
},
threeDotsAnchorPosition = {
vertical: 0,
horizontal: 0,
Expand Down Expand Up @@ -141,7 +137,6 @@ function HeaderWithBackButton({
menuItems={threeDotsMenuItems}
onIconPress={onThreeDotsButtonPress}
anchorPosition={threeDotsAnchorPosition}
anchorAlignment={threeDotsAnchorAlignment}
/>
)}
{shouldShowCloseButton && (
Expand Down
2 changes: 1 addition & 1 deletion src/components/KYCWall/BaseKYCWall.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class KYCWall extends React.Component {
}

return {
anchorPositionVertical: domRect.top - 8,
anchorPositionVertical: domRect.top - CONST.MODAL.POPOVER_MENU_PADDING,
anchorPositionHorizontal: domRect.left,
};
}
Expand Down
1 change: 0 additions & 1 deletion src/components/MoneyReportHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ function MoneyReportHeader(props) {
<HeaderWithBackButton
shouldShowAvatarWithDisplay
shouldShowPinButton={false}
shouldShowThreeDotsButton={false}
report={props.report}
policies={props.policies}
personalDetails={props.personalDetails}
Expand Down
4 changes: 4 additions & 0 deletions src/components/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ function MoneyRequestConfirmationList(props) {
currency={props.iouCurrencyCode}
policyID={props.policyID}
shouldShowPaymentOptions
anchorAlignment={{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
}}
/>
) : (
<ButtonWithDropdownMenu
Expand Down
11 changes: 11 additions & 0 deletions src/components/SettlementButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ const propTypes = {
/** Total money amount in form <currency><amount> */
formattedAmount: PropTypes.string,

/** The anchor alignment of the popover menu */
anchorAlignment: PropTypes.shape({
horizontal: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL)),
vertical: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_VERTICAL)),
}),

...withLocalizePropTypes,
};

Expand All @@ -71,6 +77,10 @@ const defaultProps = {
iouReport: {},
policyID: '',
formattedAmount: '',
anchorAlignment: {
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, // we assume that popover menu opens below the button, anchor is at TOP
},
};

class SettlementButton extends React.Component {
Expand Down Expand Up @@ -178,6 +188,7 @@ class SettlementButton extends React.Component {
}}
options={this.getButtonOptionsFromProps()}
style={this.props.style}
anchorAlignment={this.props.anchorAlignment}
/>
)}
</KYCWall>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ThreeDotsMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const defaultProps = {
onIconPress: () => {},
anchorAlignment: {
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, // we assume that popover menu opens below the button, anchor is at TOP
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ function BasePaymentsPage(props) {
onClose={hideAddPaymentMenu}
anchorPosition={{
horizontal: anchorPosition.anchorPositionHorizontal,
vertical: anchorPosition.anchorPositionVertical - 10,
vertical: anchorPosition.anchorPositionVertical - CONST.MODAL.POPOVER_MENU_PADDING,
}}
onItemSelected={(method) => addPaymentMethodTypePressed(method)}
anchorRef={addPaymentMethodAnchorRef}
Expand Down

0 comments on commit 474a8f1

Please sign in to comment.