Skip to content

Commit

Permalink
Merge pull request #28744 from Nikhil-Vats/26070_fix_popover_position
Browse files Browse the repository at this point in the history
Fix popover position for payment buttons
  • Loading branch information
marcochavezf authored Oct 5, 2023
2 parents 74ce732 + 3ba03d1 commit 8d42ad3
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 9 deletions.
12 changes: 12 additions & 0 deletions src/components/AddPaymentMethodMenu.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'underscore';
import React from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
Expand All @@ -24,6 +25,12 @@ const propTypes = {
vertical: PropTypes.number,
}),

/** Where the popover should be positioned relative to the anchor points. */
anchorAlignment: PropTypes.shape({
horizontal: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL)),
vertical: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_VERTICAL)),
}),

/** List of betas available to current user */
betas: PropTypes.arrayOf(PropTypes.string),

Expand All @@ -35,6 +42,10 @@ const propTypes = {

const defaultProps = {
anchorPosition: {},
anchorAlignment: {
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
},
betas: [],
anchorRef: () => {},
};
Expand All @@ -45,6 +56,7 @@ function AddPaymentMethodMenu(props) {
isVisible={props.isVisible}
onClose={props.onClose}
anchorPosition={props.anchorPosition}
anchorAlignment={props.anchorAlignment}
anchorRef={props.anchorRef}
onItemSelected={props.onClose}
menuItems={[
Expand Down
1 change: 1 addition & 0 deletions src/components/ButtonWithDropdownMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ function ButtonWithDropdownMenu(props) {
) : (
<Button
success
ref={props.buttonRef}
pressOnEnter={props.pressOnEnter}
isDisabled={props.isDisabled}
style={[styles.w100, ...props.style]}
Expand Down
12 changes: 8 additions & 4 deletions src/components/KYCWall/BaseKYCWall.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class KYCWall extends React.Component {
* @returns {Object}
*/
getAnchorPosition(domRect) {
if (this.props.popoverPlacement === 'bottom') {
if (this.props.anchorAlignment.vertical === CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP) {
return {
anchorPositionVertical: domRect.top + (domRect.height - 2),
anchorPositionVertical: domRect.top + domRect.height + CONST.MODAL.POPOVER_MENU_PADDING,
anchorPositionHorizontal: domRect.left + 20,
};
}
Expand Down Expand Up @@ -100,7 +100,10 @@ class KYCWall extends React.Component {
this.setState({shouldShowAddPaymentMenu: false});
return;
}
this.setState({transferBalanceButton: event.nativeEvent.target});

// Use event target as fallback if anchorRef is null for safety
const targetElement = this.anchorRef.current || event.nativeEvent.target;
this.setState({transferBalanceButton: targetElement});
const isExpenseReport = ReportUtils.isExpenseReport(this.props.iouReport);
const paymentCardList = this.props.fundList || {};

Expand All @@ -110,7 +113,7 @@ class KYCWall extends React.Component {
(!isExpenseReport && !PaymentUtils.hasExpensifyPaymentMethod(paymentCardList, this.props.bankAccountList))
) {
Log.info('[KYC Wallet] User does not have valid payment method');
const clickedElementLocation = getClickedTargetLocation(event.nativeEvent.target);
const clickedElementLocation = getClickedTargetLocation(targetElement);
const position = this.getAnchorPosition(clickedElementLocation);
this.setPositionAddPaymentMenu(position);
this.setState({
Expand Down Expand Up @@ -142,6 +145,7 @@ class KYCWall extends React.Component {
vertical: this.state.anchorPositionVertical,
horizontal: this.state.anchorPositionHorizontal,
}}
anchorAlignment={this.props.anchorAlignment}
onItemSelected={(item) => {
this.setState({shouldShowAddPaymentMenu: false});
if (item === CONST.PAYMENT_METHODS.BANK_ACCOUNT) {
Expand Down
16 changes: 12 additions & 4 deletions src/components/KYCWall/kycWallPropTypes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import _ from 'underscore';
import PropTypes from 'prop-types';
import userWalletPropTypes from '../../pages/EnablePayments/userWalletPropTypes';
import bankAccountPropTypes from '../bankAccountPropTypes';
import cardPropTypes from '../cardPropTypes';
import iouReportPropTypes from '../../pages/iouReportPropTypes';
import reimbursementAccountPropTypes from '../../pages/ReimbursementAccount/ReimbursementAccountDraftPropTypes';
import CONST from '../../CONST';

const propTypes = {
/** Route for the Add Bank Account screen for a given navigation stack */
Expand All @@ -15,9 +17,6 @@ const propTypes = {
/** Route for the KYC enable payments screen for a given navigation stack */
enablePaymentsRoute: PropTypes.string.isRequired,

/** Where to place the popover */
popoverPlacement: PropTypes.string,

/** Listen for window resize event on web and desktop */
shouldListenForResize: PropTypes.bool,

Expand All @@ -44,11 +43,16 @@ const propTypes = {

/** The reimbursement account linked to the Workspace */
reimbursementAccount: reimbursementAccountPropTypes,

/** Where the popover should be positioned relative to the anchor points. */
anchorAlignment: PropTypes.shape({
horizontal: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL)),
vertical: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_VERTICAL)),
}),
};

const defaultProps = {
userWallet: {},
popoverPlacement: 'top',
shouldListenForResize: false,
isDisabled: false,
chatReportID: '',
Expand All @@ -58,6 +62,10 @@ const defaultProps = {
reimbursementAccount: {},
addDebitCardRoute: '',
iouReport: {},
anchorAlignment: {
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
},
};

export {propTypes, defaultProps};
4 changes: 4 additions & 0 deletions src/components/MoneyReportHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ function MoneyReportHeader({session, personalDetails, policy, chatReport, report
shouldShowPaymentOptions
style={[styles.pv2]}
formattedAmount={formattedAmount}
anchorAlignment={{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP,
}}
/>
</View>
)}
Expand Down
4 changes: 4 additions & 0 deletions src/components/ReportActionItem/ReportPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ function ReportPreview(props) {
enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS}
addBankAccountRoute={bankAccountRoute}
style={[styles.requestPreviewBox]}
anchorAlignment={{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
}}
/>
)}
</View>
Expand Down
1 change: 1 addition & 0 deletions src/components/SettlementButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ function SettlementButton({
isDisabled={isOffline}
chatReportID={chatReportID}
iouReport={iouReport}
anchorAlignment={anchorAlignment}
>
{(triggerKYCFlow, buttonRef) => (
<ButtonWithDropdownMenu
Expand Down
5 changes: 4 additions & 1 deletion src/pages/settings/Wallet/WalletPage/BaseWalletPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ function BaseWalletPage(props) {
enablePaymentsRoute={ROUTES.SETTINGS_ENABLE_PAYMENTS}
addBankAccountRoute={ROUTES.SETTINGS_ADD_BANK_ACCOUNT}
addDebitCardRoute={ROUTES.SETTINGS_ADD_DEBIT_CARD}
popoverPlacement="bottom"
anchorAlignment={{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP,
}}
>
{(triggerKYCFlow, buttonRef) => (
<MenuItem
Expand Down

0 comments on commit 8d42ad3

Please sign in to comment.