Skip to content

Commit

Permalink
Merge pull request #46507 from bernhardoj/fix/32116-keyboard-shows-wh…
Browse files Browse the repository at this point in the history
…en-open-ba-page

Fix keyboard shows briefly when open BA page from payment method popover menu
  • Loading branch information
rlinoz authored Aug 6, 2024
2 parents 41e27c9 + c9a617b commit 1eef6f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/components/AddPaymentMethodMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {RefObject} from 'react';
import React, {useEffect} from 'react';
import React, {useEffect, useState} from 'react';
import type {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
Expand All @@ -13,6 +13,7 @@ import type {Report, Session} from '@src/types/onyx';
import type AnchorAlignment from '@src/types/utils/AnchorAlignment';
import * as Expensicons from './Icon/Expensicons';
import type {PaymentMethod} from './KYCWall/types';
import type BaseModalProps from './Modal/types';
import PopoverMenu from './PopoverMenu';

type AddPaymentMethodMenuOnyxProps = {
Expand Down Expand Up @@ -61,6 +62,7 @@ function AddPaymentMethodMenu({
shouldShowPersonalBankAccountOption = false,
}: AddPaymentMethodMenuProps) {
const {translate} = useLocalize();
const [restoreFocusType, setRestoreFocusType] = useState<BaseModalProps['restoreFocusType']>();

// Users can choose to pay with business bank account in case of Expense reports or in case of P2P IOU report
// which then starts a bottom up flow and creates a Collect workspace where the payer is an admin and payee is an employee.
Expand Down Expand Up @@ -88,11 +90,17 @@ function AddPaymentMethodMenu({
return (
<PopoverMenu
isVisible={isVisible}
onClose={onClose}
onClose={() => {
setRestoreFocusType(undefined);
onClose();
}}
anchorPosition={anchorPosition}
anchorAlignment={anchorAlignment}
anchorRef={anchorRef}
onItemSelected={onClose}
onItemSelected={() => {
setRestoreFocusType(CONST.MODAL.RESTORE_FOCUS_TYPE.DELETE);
onClose();
}}
menuItems={[
...(canUsePersonalBankAccount
? [
Expand Down Expand Up @@ -124,6 +132,8 @@ function AddPaymentMethodMenu({
// ],
]}
withoutOverlay
shouldEnableNewFocusManagement
restoreFocusType={restoreFocusType}
/>
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/components/PopoverMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import FocusTrapForModal from './FocusTrap/FocusTrapForModal';
import * as Expensicons from './Icon/Expensicons';
import type {MenuItemProps} from './MenuItem';
import MenuItem from './MenuItem';
import type BaseModalProps from './Modal/types';
import PopoverWithMeasuredContent from './PopoverWithMeasuredContent';
import Text from './Text';

Expand Down Expand Up @@ -83,6 +84,9 @@ type PopoverMenuProps = Partial<PopoverModalProps> & {
* We are attempting to migrate to a new refocus manager, adding this property for gradual migration.
* */
shouldEnableNewFocusManagement?: boolean;

/** How to re-focus after the modal is dismissed */
restoreFocusType?: BaseModalProps['restoreFocusType'];
};

function PopoverMenu({
Expand All @@ -106,6 +110,7 @@ function PopoverMenu({
withoutOverlay = false,
shouldSetModalVisibility = true,
shouldEnableNewFocusManagement,
restoreFocusType,
}: PopoverMenuProps) {
const styles = useThemeStyles();
const theme = useTheme();
Expand Down Expand Up @@ -218,6 +223,7 @@ function PopoverMenu({
withoutOverlay={withoutOverlay}
shouldSetModalVisibility={shouldSetModalVisibility}
shouldEnableNewFocusManagement={shouldEnableNewFocusManagement}
restoreFocusType={restoreFocusType}
>
<FocusTrapForModal active={isVisible}>
<View style={isSmallScreenWidth ? {} : styles.createMenuContainer}>
Expand Down

0 comments on commit 1eef6f5

Please sign in to comment.