diff --git a/src/CONST.js b/src/CONST.js index 305f981e8b77..73989ebf33a0 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -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', diff --git a/src/components/ButtonWithDropdownMenu.js b/src/components/ButtonWithDropdownMenu.js index 2bb21dd78f28..5c1a95b8755f 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 ( @@ -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, 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/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/MoneyReportHeader.js b/src/components/MoneyReportHeader.js index 71ac5e02467b..c4ce8cd173f1 100644 --- a/src/components/MoneyReportHeader.js +++ b/src/components/MoneyReportHeader.js @@ -68,7 +68,6 @@ function MoneyReportHeader(props) { ) : ( */ 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/components/ThreeDotsMenu/index.js b/src/components/ThreeDotsMenu/index.js index 07671eeb0369..c60060144099 100644 --- a/src/components/ThreeDotsMenu/index.js +++ b/src/components/ThreeDotsMenu/index.js @@ -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 }, }; diff --git a/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js b/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js index beaf26de265f..5b8d777608ed 100644 --- a/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js +++ b/src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js @@ -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}