diff --git a/src/components/SelectionListWithModal/index.tsx b/src/components/SelectionListWithModal/index.tsx index ca34e579a431..2d218bc815fe 100644 --- a/src/components/SelectionListWithModal/index.tsx +++ b/src/components/SelectionListWithModal/index.tsx @@ -23,13 +23,15 @@ function SelectionListWithModal( const [isModalVisible, setIsModalVisible] = useState(false); const [longPressedItem, setLongPressedItem] = useState(null); const {translate} = useLocalize(); - const {shouldUseNarrowLayout} = useResponsiveLayout(); + // We need to use isSmallScreenWidth instead of shouldUseNarrowLayout here because there is a race condition that causes shouldUseNarrowLayout to change indefinitely in this component + // See https://github.com/Expensify/App/issues/48675 for more details + const {isSmallScreenWidth} = useResponsiveLayout(); const {selectionMode} = useMobileSelectionMode(true); useEffect(() => { // We can access 0 index safely as we are not displaying multiple sections in table view const selectedItems = sections[0].data.filter((item) => item.isSelected); - if (!shouldUseNarrowLayout) { + if (!isSmallScreenWidth) { if (selectedItems.length === 0) { turnOffMobileSelectionMode(); } @@ -38,11 +40,11 @@ function SelectionListWithModal( if (selectedItems.length > 0 && !selectionMode?.isEnabled) { turnOnMobileSelectionMode(); } - }, [sections, selectionMode, shouldUseNarrowLayout]); + }, [sections, selectionMode, isSmallScreenWidth]); const handleLongPressRow = (item: TItem) => { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - if (!turnOnSelectionModeOnLongPress || !shouldUseNarrowLayout || item?.isDisabled || item?.isDisabledCheckbox) { + if (!turnOnSelectionModeOnLongPress || !isSmallScreenWidth || item?.isDisabled || item?.isDisabledCheckbox) { return; } setLongPressedItem(item); diff --git a/src/pages/workspace/reportFields/ReportFieldsListValuesPage.tsx b/src/pages/workspace/reportFields/ReportFieldsListValuesPage.tsx index bf5599b6283f..8cbb9cd177e3 100644 --- a/src/pages/workspace/reportFields/ReportFieldsListValuesPage.tsx +++ b/src/pages/workspace/reportFields/ReportFieldsListValuesPage.tsx @@ -59,7 +59,9 @@ function ReportFieldsListValuesPage({ }: ReportFieldsListValuesPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); - const {shouldUseNarrowLayout} = useResponsiveLayout(); + // We need to use isSmallScreenWidth instead of shouldUseNarrowLayout here to use the mobile selection mode on small screens only + // See https://github.com/Expensify/App/issues/48724 for more details + const {isSmallScreenWidth} = useResponsiveLayout(); const [formDraft] = useOnyx(ONYXKEYS.FORMS.WORKSPACE_REPORT_FIELDS_FORM_DRAFT); const {selectionMode} = useMobileSelectionMode(); @@ -67,7 +69,7 @@ function ReportFieldsListValuesPage({ const [deleteValuesConfirmModalVisible, setDeleteValuesConfirmModalVisible] = useState(false); const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy); - const canSelectMultiple = !hasAccountingConnections && (shouldUseNarrowLayout ? selectionMode?.isEnabled : true); + const canSelectMultiple = !hasAccountingConnections && (isSmallScreenWidth ? selectionMode?.isEnabled : true); const [listValues, disabledListValues] = useMemo(() => { let reportFieldValues: string[]; @@ -177,7 +179,7 @@ function ReportFieldsListValuesPage({ const getHeaderButtons = () => { const options: Array>> = []; - if (shouldUseNarrowLayout ? selectionMode?.isEnabled : selectedValuesArray.length > 0) { + if (isSmallScreenWidth ? selectionMode?.isEnabled : selectedValuesArray.length > 0) { if (selectedValuesArray.length > 0) { options.push({ icon: Expensicons.Trashcan, @@ -259,7 +261,7 @@ function ReportFieldsListValuesPage({ customText={translate('workspace.common.selected', {selectedNumber: selectedValuesArray.length})} options={options} isSplitButton={false} - style={[shouldUseNarrowLayout && styles.flexGrow1, shouldUseNarrowLayout && styles.mb3]} + style={[isSmallScreenWidth && styles.flexGrow1, isSmallScreenWidth && styles.mb3]} isDisabled={!selectedValuesArray.length} /> ); @@ -267,7 +269,7 @@ function ReportFieldsListValuesPage({ return (