From fc2c0b438fa0923a51201ccee1a00b34a3776df8 Mon Sep 17 00:00:00 2001 From: Nikhil Vats Date: Tue, 1 Aug 2023 20:26:27 +0530 Subject: [PATCH 1/2] Fix position of settlement button popover menu --- src/CONST.js | 1 + src/components/ButtonWithDropdownMenu.js | 22 ++++++++++++++----- src/components/KYCWall/BaseKYCWall.js | 2 +- .../MoneyRequestConfirmationList.js | 4 ++++ src/components/SettlementButton.js | 11 ++++++++++ .../Payments/PaymentsPage/BasePaymentsPage.js | 2 +- 6 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index 06bc1873431f..dd854e517909 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -653,6 +653,7 @@ const CONST = { CENTER: 'center', RIGHT: 'right', }, + POPOVER_MENU_PADDING: 8, }, TIMING: { CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION: 'calc_most_recent_last_modified_action', diff --git a/src/components/ButtonWithDropdownMenu.js b/src/components/ButtonWithDropdownMenu.js index 1396ab601330..ac87da783a66 100644 --- a/src/components/ButtonWithDropdownMenu.js +++ b/src/components/ButtonWithDropdownMenu.js @@ -39,6 +39,12 @@ 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 = { @@ -46,6 +52,10 @@ const defaultProps = { 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) { @@ -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 ( @@ -117,10 +130,7 @@ function ButtonWithDropdownMenu(props) { onClose={() => setIsMenuVisible(false)} onItemSelected={() => setIsMenuVisible(false)} anchorPosition={popoverAnchorPosition} - 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, diff --git a/src/components/KYCWall/BaseKYCWall.js b/src/components/KYCWall/BaseKYCWall.js index 2a583af74639..534f00b7f746 100644 --- a/src/components/KYCWall/BaseKYCWall.js +++ b/src/components/KYCWall/BaseKYCWall.js @@ -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, }; } diff --git a/src/components/MoneyRequestConfirmationList.js b/src/components/MoneyRequestConfirmationList.js index b376e02b1095..91c9a827f311 100755 --- a/src/components/MoneyRequestConfirmationList.js +++ b/src/components/MoneyRequestConfirmationList.js @@ -263,6 +263,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, + }} /> ) : ( */ 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, }; @@ -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 { @@ -178,6 +188,7 @@ class SettlementButton extends React.Component { }} options={this.getButtonOptionsFromProps()} style={this.props.style} + anchorAlignment={this.props.anchorAlignment} /> )} diff --git a/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js b/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js index 780115ea6792..5cacbd1fd843 100644 --- a/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js +++ b/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js @@ -421,7 +421,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)} /> From 742cea293eac00a0522bf249fb7427f04c01d7bf Mon Sep 17 00:00:00 2001 From: Nikhil Vats Date: Tue, 1 Aug 2023 20:57:43 +0530 Subject: [PATCH 2/2] Fix task header three dots menu popover position --- .../HeaderWithBackButton/headerWithBackButtonPropTypes.js | 8 -------- src/components/HeaderWithBackButton/index.js | 5 ----- src/components/MoneyReportHeader.js | 1 - src/components/ThreeDotsMenu/index.js | 2 +- 4 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/components/HeaderWithBackButton/headerWithBackButtonPropTypes.js b/src/components/HeaderWithBackButton/headerWithBackButtonPropTypes.js index a1311433f2d3..a5f1c81823b0 100644 --- a/src/components/HeaderWithBackButton/headerWithBackButtonPropTypes.js +++ b/src/components/HeaderWithBackButton/headerWithBackButtonPropTypes.js @@ -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'; @@ -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, diff --git a/src/components/HeaderWithBackButton/index.js b/src/components/HeaderWithBackButton/index.js index e5b22f6ccf5d..6e6164f4c4fc 100755 --- a/src/components/HeaderWithBackButton/index.js +++ b/src/components/HeaderWithBackButton/index.js @@ -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, @@ -141,7 +137,6 @@ function HeaderWithBackButton({ menuItems={threeDotsMenuItems} onIconPress={onThreeDotsButtonPress} anchorPosition={threeDotsAnchorPosition} - anchorAlignment={threeDotsAnchorAlignment} /> )} {shouldShowCloseButton && ( diff --git a/src/components/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index 01b0418c6ea8..b9a5d481218b 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -67,7 +67,6 @@ function MoneyReportHeader(props) { {}, 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 }, };