Skip to content

Commit

Permalink
Merge pull request Expensify#27653 from Krishna2323/krishna2323/issue…
Browse files Browse the repository at this point in the history
…/27182

fix: Refocus issue on address field on delete and cancel
  • Loading branch information
amyevans authored Sep 22, 2023
2 parents 9ab20c5 + 9514e23 commit 28987c4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/components/HeaderWithBackButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function HeaderWithBackButton({
},
threeDotsMenuItems = [],
children = null,
onModalHide = () => {},
shouldOverlay = false,
}) {
const [isDownloadButtonActive, temporarilyDisableDownloadButton] = useThrottledButtonState();
Expand Down Expand Up @@ -138,6 +139,7 @@ function HeaderWithBackButton({
menuItems={threeDotsMenuItems}
onIconPress={onThreeDotsButtonPress}
anchorPosition={threeDotsAnchorPosition}
onModalHide={onModalHide}
shouldOverlay={shouldOverlay}
/>
)}
Expand Down
5 changes: 5 additions & 0 deletions src/components/PopoverMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const propTypes = {
}),

withoutOverlay: PropTypes.bool,

/** Function to call on modal hide */
onModalHide: PropTypes.func,
};

const defaultProps = {
Expand All @@ -44,6 +47,7 @@ const defaultProps = {
},
anchorRef: () => {},
withoutOverlay: false,
onModalHide: () => {},
};

function PopoverMenu(props) {
Expand Down Expand Up @@ -78,6 +82,7 @@ function PopoverMenu(props) {
isVisible={props.isVisible}
onModalHide={() => {
setFocusedIndex(-1);
props.onModalHide();
if (selectedItemIndex.current !== null) {
props.menuItems[selectedItemIndex.current].onSelected();
selectedItemIndex.current = null;
Expand Down
12 changes: 10 additions & 2 deletions src/components/ThreeDotsMenu/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useState, useRef} from 'react';
import {View} from 'react-native';
import {InteractionManager, View} from 'react-native';
import PropTypes from 'prop-types';
import _ from 'underscore';
import Icon from '../Icon';
Expand Down Expand Up @@ -46,6 +46,9 @@ const propTypes = {
vertical: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_VERTICAL)),
}),

/** Function to call on modal hide */
onModalHide: PropTypes.func,

/** Whether the popover menu should overlay the current view */
shouldOverlay: PropTypes.bool,
};
Expand All @@ -60,10 +63,11 @@ const defaultProps = {
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, // we assume that popover menu opens below the button, anchor is at TOP
},
onModalHide: () => {},
shouldOverlay: false,
};

function ThreeDotsMenu({iconTooltip, icon, iconFill, iconStyles, onIconPress, menuItems, anchorPosition, anchorAlignment, shouldOverlay}) {
function ThreeDotsMenu({iconTooltip, icon, iconFill, iconStyles, onIconPress, menuItems, anchorPosition, anchorAlignment, onModalHide, shouldOverlay}) {
const [isPopupMenuVisible, setPopupMenuVisible] = useState(false);
const buttonRef = useRef(null);
const {translate} = useLocalize();
Expand All @@ -73,6 +77,9 @@ function ThreeDotsMenu({iconTooltip, icon, iconFill, iconStyles, onIconPress, me
};

const hidePopoverMenu = () => {
InteractionManager.runAfterInteractions(() => {
onModalHide();
});
setPopupMenuVisible(false);
};

Expand Down Expand Up @@ -105,6 +112,7 @@ function ThreeDotsMenu({iconTooltip, icon, iconFill, iconStyles, onIconPress, me
</View>
<PopoverMenu
onClose={hidePopoverMenu}
onPopoverHide={onModalHide}
isVisible={isPopupMenuVisible}
anchorPosition={anchorPosition}
anchorAlignment={anchorAlignment}
Expand Down
13 changes: 12 additions & 1 deletion src/pages/iou/WaypointEditor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useMemo, useRef, useState} from 'react';
import _ from 'underscore';
import lodashGet from 'lodash/get';
import {View} from 'react-native';
import {InteractionManager, View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import {useIsFocused} from '@react-navigation/native';
Expand Down Expand Up @@ -166,6 +166,15 @@ function WaypointEditor({transactionID, route: {params: {iouType = '', waypointI
Navigation.goBack(ROUTES.getMoneyRequestDistanceTabRoute(iouType));
};

const focusAddressInput = () => {
InteractionManager.runAfterInteractions(() => {
if (!textInput.current) {
return;
}
textInput.current.focus();
});
};

return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
Expand All @@ -188,12 +197,14 @@ function WaypointEditor({transactionID, route: {params: {iouType = '', waypointI
onSelected: () => setIsDeleteStopModalOpen(true),
},
]}
onModalHide={focusAddressInput}
/>
<ConfirmModal
title={translate('distance.deleteWaypoint')}
isVisible={isDeleteStopModalOpen}
onConfirm={deleteStopAndHideModal}
onCancel={() => setIsDeleteStopModalOpen(false)}
onModalHide={focusAddressInput}
prompt={translate('distance.deleteWaypointConfirmation')}
confirmText={translate('common.delete')}
cancelText={translate('common.cancel')}
Expand Down

0 comments on commit 28987c4

Please sign in to comment.