Skip to content

Commit 9d86f30

Browse files
authored
Merge pull request #50575 from Expensify/revert-49510-fix/49084
[CP Staging] Revert "fix: search header flickering on selection mode"
2 parents 36c45f4 + f030433 commit 9d86f30

File tree

2 files changed

+6
-40
lines changed

2 files changed

+6
-40
lines changed

src/components/Search/index.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr
9191
const {isSmallScreenWidth, isLargeScreenWidth} = useResponsiveLayout();
9292
const navigation = useNavigation<StackNavigationProp<AuthScreensParamList>>();
9393
const lastSearchResultsRef = useRef<OnyxEntry<SearchResults>>();
94-
const {selectionMode} = useMobileSelectionMode(false);
9594
const {setCurrentSearchHash, setSelectedTransactions, selectedTransactions, clearSelectedTransactions, setShouldShowStatusBarLoading} = useSearchContext();
95+
const {selectionMode} = useMobileSelectionMode();
9696
const [offset, setOffset] = useState(0);
9797

9898
const {type, status, sortBy, sortOrder, hash} = queryJSON;
@@ -379,11 +379,6 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr
379379
onTurnOnSelectionMode={(item) => item && toggleTransaction(item)}
380380
onCheckboxPress={toggleTransaction}
381381
onSelectAll={toggleAllTransactions}
382-
isSelected={(item) =>
383-
status !== CONST.SEARCH.STATUS.EXPENSE.ALL && SearchUtils.isReportListItemType(item)
384-
? item.transactions.some((transaction) => selectedTransactions[transaction.keyForList]?.isSelected)
385-
: !!item.isSelected
386-
}
387382
customListHeader={
388383
!isLargeScreenWidth ? null : (
389384
<SearchTableHeader
@@ -397,7 +392,6 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr
397392
/>
398393
)
399394
}
400-
shouldAutoTurnOff={false}
401395
onScroll={onSearchListScroll}
402396
canSelectMultiple={type !== CONST.SEARCH.DATA_TYPES.CHAT && canSelectMultiple}
403397
customListHeaderHeight={searchHeaderHeight}

src/components/SelectionListWithModal/index.tsx

+5-33
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {ForwardedRef} from 'react';
2-
import React, {forwardRef, useEffect, useRef, useState} from 'react';
2+
import React, {forwardRef, useEffect, useState} from 'react';
33
import * as Expensicons from '@components/Icon/Expensicons';
44
import MenuItem from '@components/MenuItem';
55
import Modal from '@components/Modal';
@@ -14,12 +14,10 @@ import CONST from '@src/CONST';
1414
type SelectionListWithModalProps<TItem extends ListItem> = BaseSelectionListProps<TItem> & {
1515
turnOnSelectionModeOnLongPress?: boolean;
1616
onTurnOnSelectionMode?: (item: TItem | null) => void;
17-
shouldAutoTurnOff?: boolean;
18-
isSelected?: (item: TItem) => boolean;
1917
};
2018

2119
function SelectionListWithModal<TItem extends ListItem>(
22-
{turnOnSelectionModeOnLongPress, onTurnOnSelectionMode, onLongPressRow, sections, shouldAutoTurnOff, isSelected, ...rest}: SelectionListWithModalProps<TItem>,
20+
{turnOnSelectionModeOnLongPress, onTurnOnSelectionMode, onLongPressRow, sections, ...rest}: SelectionListWithModalProps<TItem>,
2321
ref: ForwardedRef<SelectionListHandle>,
2422
) {
2523
const [isModalVisible, setIsModalVisible] = useState(false);
@@ -28,47 +26,21 @@ function SelectionListWithModal<TItem extends ListItem>(
2826
// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout here because there is a race condition that causes shouldUseNarrowLayout to change indefinitely in this component
2927
// See https://github.com/Expensify/App/issues/48675 for more details
3028
const {isSmallScreenWidth} = useResponsiveLayout();
31-
const {selectionMode} = useMobileSelectionMode(shouldAutoTurnOff);
32-
// Check if selection should be on when the modal is opened
33-
const wasSelectionOnRef = useRef(false);
34-
// Keep track of the number of selected items to determine if we should turn off selection mode
35-
const selectionRef = useRef(0);
29+
const {selectionMode} = useMobileSelectionMode(true);
3630

3731
useEffect(() => {
3832
// We can access 0 index safely as we are not displaying multiple sections in table view
39-
const selectedItems = sections[0].data.filter((item) => {
40-
if (isSelected) {
41-
return isSelected(item);
42-
}
43-
return !!item.isSelected;
44-
});
45-
selectionRef.current = selectedItems.length;
46-
33+
const selectedItems = sections[0].data.filter((item) => item.isSelected);
4734
if (!isSmallScreenWidth) {
4835
if (selectedItems.length === 0) {
4936
turnOffMobileSelectionMode();
5037
}
5138
return;
5239
}
53-
if (!wasSelectionOnRef.current && selectedItems.length > 0) {
54-
wasSelectionOnRef.current = true;
55-
}
5640
if (selectedItems.length > 0 && !selectionMode?.isEnabled) {
5741
turnOnMobileSelectionMode();
58-
} else if (selectedItems.length === 0 && selectionMode?.isEnabled && !wasSelectionOnRef.current) {
59-
turnOffMobileSelectionMode();
6042
}
61-
}, [sections, selectionMode, isSmallScreenWidth, isSelected]);
62-
63-
useEffect(
64-
() => () => {
65-
if (selectionRef.current !== 0) {
66-
return;
67-
}
68-
turnOffMobileSelectionMode();
69-
},
70-
[],
71-
);
43+
}, [sections, selectionMode, isSmallScreenWidth]);
7244

7345
const handleLongPressRow = (item: TItem) => {
7446
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing

0 commit comments

Comments
 (0)