Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions src/components/AvatarWithImagePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as FileUtils from '@libs/fileDownload/FileUtils';
import getImageResolution from '@libs/fileDownload/getImageResolution';
import type {AvatarSource} from '@libs/UserUtils';
import variables from '@styles/variables';
import * as Modal from '@userActions/Modal';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
Expand Down Expand Up @@ -263,14 +264,15 @@ function AvatarWithImagePicker({
{
icon: Expensicons.Upload,
text: translate('avatarWithImagePicker.uploadPhoto'),
onSelected: () => {
if (Browser.isSafari()) {
return;
}
openPicker({
onPicked: showAvatarCropModal,
});
},
onSelected: () =>
Modal.close(() => {
Comment thread
zfurtak marked this conversation as resolved.
if (Browser.isSafari()) {
return;
}
openPicker({
onPicked: showAvatarCropModal,
});
}),
},
];

Expand Down Expand Up @@ -342,13 +344,14 @@ function AvatarWithImagePicker({
menuItems.push({
icon: Expensicons.Eye,
text: translate('avatarWithImagePicker.viewPhoto'),
onSelected: () => {
if (typeof onViewPhotoPress !== 'function') {
show();
return;
}
onViewPhotoPress();
},
onSelected: () =>
Modal.close(() => {
if (typeof onViewPhotoPress !== 'function') {
show();
return;
}
onViewPhotoPress();
}),
});
}

Expand Down
13 changes: 7 additions & 6 deletions src/components/ButtonWithDropdownMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as Modal from '@userActions/Modal';
import CONST from '@src/CONST';
import type {AnchorPosition} from '@src/styles';
import type {ButtonWithDropdownMenuProps} from './types';
Expand Down Expand Up @@ -145,12 +146,12 @@ function ButtonWithDropdownMenu<IValueType>({
headerText={menuHeaderText}
menuItems={options.map((item, index) => ({
...item,
onSelected:
item.onSelected ??
(() => {
onOptionSelected?.(item);
setSelectedItemIndex(index);
}),
onSelected: item.onSelected
? () => Modal.close(() => item.onSelected?.())
: () => {
onOptionSelected?.(item);
setSelectedItemIndex(index);
},
}))}
/>
)}
Expand Down
10 changes: 2 additions & 8 deletions src/components/PopoverMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import lodashIsEqual from 'lodash/isEqual';
import type {RefObject} from 'react';
import React, {useEffect, useRef, useState} from 'react';
import React, {useEffect, useState} from 'react';
import {StyleSheet, View} from 'react-native';
import type {ModalProps} from 'react-native-modal';
import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager';
Expand Down Expand Up @@ -106,8 +106,6 @@ function PopoverMenu({
const styles = useThemeStyles();
const theme = useTheme();
const {isSmallScreenWidth} = useResponsiveLayout();
const selectedItemIndex = useRef<number | null>(null);

const [currentMenuItems, setCurrentMenuItems] = useState(menuItems);
const currentMenuItemsFocusedIndex = currentMenuItems?.findIndex((option) => option.isSelected);
const [enteredSubMenuIndexes, setEnteredSubMenuIndexes] = useState<number[]>([]);
Expand All @@ -122,8 +120,8 @@ function PopoverMenu({
const selectedSubMenuItemIndex = selectedItem?.subMenuItems.findIndex((option) => option.isSelected);
setFocusedIndex(selectedSubMenuItemIndex);
} else {
selectedItemIndex.current = index;
onItemSelected(selectedItem, index);
selectedItem.onSelected?.();
Comment on lines 123 to +124

@aldo-expensify aldo-expensify Aug 2, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this file caused a regression: #46746

I'm trying to understand this component, why do we have two callbacks when we click a menu item? onItemSelected / selectedItem.onSelected?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can ignore that question, I see that they are just two "types" of callback, and in the broken flow onItemSelected(selectedItem, index) takes care of closing the context menu (menu opened with the 3 dots), meanwhile selectedItem.onSelected?.(); is supposed to open the next confirmation modal.

I think the difference in the implementation is that now selectedItem.onSelected?.(); gets called earlier. Before it was called in the onModalHide callback.

}
};

Expand Down Expand Up @@ -185,10 +183,6 @@ function PopoverMenu({

const onModalHide = () => {
setFocusedIndex(-1);
if (selectedItemIndex.current !== null) {
currentMenuItems[selectedItemIndex.current].onSelected?.();
selectedItemIndex.current = null;
}
};

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Navigation from '@libs/Navigation/Navigation';
import * as ReportUtils from '@libs/ReportUtils';
import * as SubscriptionUtils from '@libs/SubscriptionUtils';
import * as IOU from '@userActions/IOU';
import * as Modal from '@userActions/Modal';
import * as Report from '@userActions/Report';
import * as Task from '@userActions/Task';
import type {IOUType} from '@src/CONST';
Expand Down Expand Up @@ -224,12 +225,13 @@ function AttachmentPickerWithMenuItems({
{
icon: Expensicons.Paperclip,
text: translate('reportActionCompose.addAttachment'),
onSelected: () => {
if (Browser.isSafari()) {
return;
}
triggerAttachmentPicker();
},
onSelected: () =>
Modal.close(() => {
if (Browser.isSafari()) {
return;
}
triggerAttachmentPicker();
}),
},
];
return (
Expand Down
12 changes: 7 additions & 5 deletions src/pages/workspace/WorkspacesListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import type {AvatarSource} from '@libs/UserUtils';
import * as App from '@userActions/App';
import * as Modal from '@userActions/Modal';
import * as Policy from '@userActions/Policy/Policy';
import * as Session from '@userActions/Session';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -161,11 +162,12 @@ function WorkspacesListPage({policies, reimbursementAccount, reports, session}:
threeDotsMenuItems.push({
icon: Expensicons.Trashcan,
text: translate('workspace.common.delete'),
onSelected: () => {
setPolicyIDToDelete(item.policyID ?? '-1');
setPolicyNameToDelete(item.title);
setIsDeleteModalOpen(true);
},
onSelected: () =>
Modal.close(() => {
setPolicyIDToDelete(item.policyID ?? '-1');
setPolicyNameToDelete(item.title);
setIsDeleteModalOpen(true);
}),
});
}

Expand Down