diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 8caa14a338d7..9aa99e8d5903 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -1,4 +1,4 @@ -import {useNavigation} from '@react-navigation/native'; +import {useIsFocused, useNavigation} from '@react-navigation/native'; import type {StackNavigationProp} from '@react-navigation/stack'; import React, {useCallback, useEffect, useRef, useState} from 'react'; import {View} from 'react-native'; @@ -21,6 +21,7 @@ import * as SearchActions from '@libs/actions/Search'; import * as DeviceCapabilities from '@libs/DeviceCapabilities'; import Log from '@libs/Log'; import memoize from '@libs/memoize'; +import isSearchTopmostCentralPane from '@libs/Navigation/isSearchTopmostCentralPane'; import * as ReportUtils from '@libs/ReportUtils'; import * as SearchUtils from '@libs/SearchUtils'; import Navigation from '@navigation/Navigation'; @@ -92,6 +93,7 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth const {isSmallScreenWidth, isLargeScreenWidth} = useResponsiveLayout(); const navigation = useNavigation>(); + const isFocused = useIsFocused(); const lastSearchResultsRef = useRef>(); const {setCurrentSearchHash, setSelectedTransactions, selectedTransactions, clearSelectedTransactions, setShouldShowStatusBarLoading, lastSearchType, setLastSearchType} = useSearchContext(); @@ -248,6 +250,17 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr turnOffMobileSelectionMode(); }, [isSearchResultsEmpty, prevIsSearchResultEmpty]); + useEffect( + () => () => { + if (isSearchTopmostCentralPane()) { + return; + } + clearSelectedTransactions(); + turnOffMobileSelectionMode(); + }, + [isFocused, clearSelectedTransactions], + ); + if (shouldShowLoadingState) { return (