Skip to content

Commit e97ee83

Browse files
authored
Merge pull request #56225 from Krishna2323/krishna2323/issue/53344_fix2
fix: On selecting a category/ tags by multiple tapping, user directed to conversation page.
2 parents 474cd0a + 01156c5 commit e97ee83

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

src/components/SelectionList/BaseSelectionList.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ function BaseSelectionList<TItem extends ListItem>(
124124
listItemTitleStyles,
125125
initialNumToRender = 12,
126126
listItemTitleContainerStyles,
127+
isScreenFocused = false,
127128
}: BaseSelectionListProps<TItem>,
128129
ref: ForwardedRef<SelectionListHandle>,
129130
) {
@@ -381,6 +382,9 @@ function BaseSelectionList<TItem extends ListItem>(
381382
*/
382383
const selectRow = useCallback(
383384
(item: TItem, indexToFocus?: number) => {
385+
if (!isFocused && !isScreenFocused) {
386+
return;
387+
}
384388
// In single-selection lists we don't care about updating the focused index, because the list is closed after selecting an item
385389
if (canSelectMultiple) {
386390
if (sections.length > 1 && !item.isSelected) {
@@ -413,6 +417,8 @@ function BaseSelectionList<TItem extends ListItem>(
413417
setFocusedIndex,
414418
onSelectRow,
415419
shouldPreventDefaultFocusOnSelectRow,
420+
isFocused,
421+
isScreenFocused,
416422
],
417423
);
418424

src/components/SelectionList/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,9 @@ type BaseSelectionListProps<TItem extends ListItem> = Partial<ChildrenProps> & {
662662

663663
/** Initial number of items to render */
664664
initialNumToRender?: number;
665+
666+
/** Whether the screen is focused or not. (useIsFocused state does not work in tab screens, e.g. SearchPageBottomTab) */
667+
isScreenFocused?: boolean;
665668
} & TRightHandSideComponent<TItem>;
666669

667670
type SelectionListHandle = {

src/components/SelectionListWithModal/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ function SelectionListWithModal<TItem extends ListItem>(
106106
ref={ref}
107107
sections={sections}
108108
onLongPressRow={handleLongPressRow}
109+
isScreenFocused={isScreenFocused}
109110
// eslint-disable-next-line react/jsx-props-no-spreading
110111
{...rest}
111112
/>

src/pages/WorkspaceSwitcherPage/index.tsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {useIsFocused} from '@react-navigation/native';
21
import React, {useCallback, useMemo} from 'react';
32
import {useOnyx} from 'react-native-onyx';
43
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
@@ -39,7 +38,6 @@ function WorkspaceSwitcherPage() {
3938
const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState('');
4039
const {translate} = useLocalize();
4140
const {activeWorkspaceID} = useActiveWorkspace();
42-
const isFocused = useIsFocused();
4341

4442
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
4543
const [reportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS);
@@ -83,17 +81,14 @@ function WorkspaceSwitcherPage() {
8381

8482
const selectPolicy = useCallback(
8583
(policyID?: string) => {
86-
if (!isFocused) {
87-
return;
88-
}
8984
const newPolicyID = policyID === activeWorkspaceID ? undefined : policyID;
9085

9186
Navigation.goBack();
9287
// On native platforms, we will see a blank screen if we navigate to a new HomeScreen route while navigating back at the same time.
9388
// Therefore we delay switching the workspace until after back navigation, using the InteractionManager.
9489
switchPolicyAfterInteractions(newPolicyID);
9590
},
96-
[activeWorkspaceID, isFocused],
91+
[activeWorkspaceID],
9792
);
9893

9994
const usersWorkspaces = useMemo<WorkspaceListItem[]>(() => {

tests/unit/BaseSelectionListTest.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as NativeNavigation from '@react-navigation/native';
12
import {fireEvent, render, screen} from '@testing-library/react-native';
23
import {SectionList} from 'react-native';
34
import BaseSelectionList from '@components/SelectionList/BaseSelectionList';
@@ -44,8 +45,17 @@ describe('BaseSelectionList', () => {
4445
);
4546
}
4647

48+
it('should not trigger item press if screen is not focused', () => {
49+
(NativeNavigation.useIsFocused as jest.Mock).mockReturnValue(false);
50+
render(<BaseListItemRenderer sections={[{data: mockSections}]} />);
51+
fireEvent.press(screen.getByTestId(`${CONST.BASE_LIST_ITEM_TEST_ID}1`));
52+
expect(onSelectRowMock).toHaveBeenCalledTimes(0);
53+
});
54+
4755
it('should handle item press correctly', () => {
56+
(NativeNavigation.useIsFocused as jest.Mock).mockReturnValue(true);
4857
render(<BaseListItemRenderer sections={[{data: mockSections}]} />);
58+
4959
fireEvent.press(screen.getByTestId(`${CONST.BASE_LIST_ITEM_TEST_ID}1`));
5060
expect(onSelectRowMock).toHaveBeenCalledWith({
5161
...mockSections.at(1),
@@ -54,6 +64,7 @@ describe('BaseSelectionList', () => {
5464
});
5565

5666
it('should update focused item when sections are updated from BE', () => {
67+
(NativeNavigation.useIsFocused as jest.Mock).mockReturnValue(true);
5768
const updatedMockSections = mockSections.map((section) => ({
5869
...section,
5970
isSelected: section.keyForList === '2',

0 commit comments

Comments
 (0)