Skip to content

Commit 474a8f1

Browse files
authored
Merge pull request #24013 from Nikhil-Vats/23140_fix_popover_menu_position
Fix popover menu position for three dots menu and settlement button
2 parents 80df2ed + 4d0df0c commit 474a8f1

File tree

10 files changed

+35
-23
lines changed

10 files changed

+35
-23
lines changed

src/CONST.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ const CONST = {
666666
CENTER: 'center',
667667
RIGHT: 'right',
668668
},
669+
POPOVER_MENU_PADDING: 8,
669670
},
670671
TIMING: {
671672
CALCULATE_MOST_RECENT_LAST_MODIFIED_ACTION: 'calc_most_recent_last_modified_action',

src/components/ButtonWithDropdownMenu.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,23 @@ const propTypes = {
3939
iconDescription: PropTypes.string,
4040
}),
4141
).isRequired,
42+
43+
/** The anchor alignment of the popover menu */
44+
anchorAlignment: PropTypes.shape({
45+
horizontal: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL)),
46+
vertical: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_VERTICAL)),
47+
}),
4248
};
4349

4450
const defaultProps = {
4551
isLoading: false,
4652
isDisabled: false,
4753
menuHeaderText: '',
4854
style: [],
55+
anchorAlignment: {
56+
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
57+
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, // we assume that popover menu opens below the button, anchor is at TOP
58+
},
4959
};
5060

5161
function ButtonWithDropdownMenu(props) {
@@ -66,10 +76,13 @@ function ButtonWithDropdownMenu(props) {
6676
caretButton.current.measureInWindow((x, y, w, h) => {
6777
setPopoverAnchorPosition({
6878
horizontal: x + w,
69-
vertical: y + h,
79+
vertical:
80+
props.anchorAlignment.vertical === CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP
81+
? 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
82+
: 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
7083
});
7184
});
72-
}, [windowWidth, windowHeight, isMenuVisible]);
85+
}, [windowWidth, windowHeight, isMenuVisible, props.anchorAlignment.vertical]);
7386

7487
return (
7588
<View>
@@ -119,10 +132,7 @@ function ButtonWithDropdownMenu(props) {
119132
anchorPosition={popoverAnchorPosition}
120133
anchorRef={caretButton}
121134
withoutOverlay
122-
anchorAlignment={{
123-
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
124-
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
125-
}}
135+
anchorAlignment={props.anchorAlignment}
126136
headerText={props.menuHeaderText}
127137
menuItems={_.map(props.options, (item, index) => ({
128138
...item,

src/components/HeaderWithBackButton/headerWithBackButtonPropTypes.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import _ from 'underscore';
21
import PropTypes from 'prop-types';
32
import {ThreeDotsMenuItemPropTypes} from '../ThreeDotsMenu';
4-
import CONST from '../../CONST';
53
import iouReportPropTypes from '../../pages/iouReportPropTypes';
64
import participantPropTypes from '../participantPropTypes';
75

@@ -50,12 +48,6 @@ const propTypes = {
5048
left: PropTypes.number,
5149
}),
5250

53-
/** The anchor alignment of the menu */
54-
threeDotsAnchorAlignment: PropTypes.shape({
55-
horizontal: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL)),
56-
vertical: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_VERTICAL)),
57-
}),
58-
5951
/** Whether we should show a close button */
6052
shouldShowCloseButton: PropTypes.bool,
6153

src/components/HeaderWithBackButton/index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ function HeaderWithBackButton({
4141
subtitle = '',
4242
title = '',
4343
titleColor = undefined,
44-
threeDotsAnchorAlignment = {
45-
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
46-
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP,
47-
},
4844
threeDotsAnchorPosition = {
4945
vertical: 0,
5046
horizontal: 0,
@@ -141,7 +137,6 @@ function HeaderWithBackButton({
141137
menuItems={threeDotsMenuItems}
142138
onIconPress={onThreeDotsButtonPress}
143139
anchorPosition={threeDotsAnchorPosition}
144-
anchorAlignment={threeDotsAnchorAlignment}
145140
/>
146141
)}
147142
{shouldShowCloseButton && (

src/components/KYCWall/BaseKYCWall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class KYCWall extends React.Component {
6969
}
7070

7171
return {
72-
anchorPositionVertical: domRect.top - 8,
72+
anchorPositionVertical: domRect.top - CONST.MODAL.POPOVER_MENU_PADDING,
7373
anchorPositionHorizontal: domRect.left,
7474
};
7575
}

src/components/MoneyReportHeader.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ function MoneyReportHeader(props) {
6868
<HeaderWithBackButton
6969
shouldShowAvatarWithDisplay
7070
shouldShowPinButton={false}
71-
shouldShowThreeDotsButton={false}
7271
report={props.report}
7372
policies={props.policies}
7473
personalDetails={props.personalDetails}

src/components/MoneyRequestConfirmationList.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ function MoneyRequestConfirmationList(props) {
303303
currency={props.iouCurrencyCode}
304304
policyID={props.policyID}
305305
shouldShowPaymentOptions
306+
anchorAlignment={{
307+
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
308+
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
309+
}}
306310
/>
307311
) : (
308312
<ButtonWithDropdownMenu

src/components/SettlementButton.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ const propTypes = {
5757
/** Total money amount in form <currency><amount> */
5858
formattedAmount: PropTypes.string,
5959

60+
/** The anchor alignment of the popover menu */
61+
anchorAlignment: PropTypes.shape({
62+
horizontal: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL)),
63+
vertical: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_VERTICAL)),
64+
}),
65+
6066
...withLocalizePropTypes,
6167
};
6268

@@ -71,6 +77,10 @@ const defaultProps = {
7177
iouReport: {},
7278
policyID: '',
7379
formattedAmount: '',
80+
anchorAlignment: {
81+
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
82+
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, // we assume that popover menu opens below the button, anchor is at TOP
83+
},
7484
};
7585

7686
class SettlementButton extends React.Component {
@@ -178,6 +188,7 @@ class SettlementButton extends React.Component {
178188
}}
179189
options={this.getButtonOptionsFromProps()}
180190
style={this.props.style}
191+
anchorAlignment={this.props.anchorAlignment}
181192
/>
182193
)}
183194
</KYCWall>

src/components/ThreeDotsMenu/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const defaultProps = {
5757
onIconPress: () => {},
5858
anchorAlignment: {
5959
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
60-
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
60+
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, // we assume that popover menu opens below the button, anchor is at TOP
6161
},
6262
};
6363

src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ function BasePaymentsPage(props) {
424424
onClose={hideAddPaymentMenu}
425425
anchorPosition={{
426426
horizontal: anchorPosition.anchorPositionHorizontal,
427-
vertical: anchorPosition.anchorPositionVertical - 10,
427+
vertical: anchorPosition.anchorPositionVertical - CONST.MODAL.POPOVER_MENU_PADDING,
428428
}}
429429
onItemSelected={(method) => addPaymentMethodTypePressed(method)}
430430
anchorRef={addPaymentMethodAnchorRef}

0 commit comments

Comments
 (0)