Skip to content

Commit 1493af6

Browse files
authored
Merge pull request #60170 from nkdengineer/fix/59643-n
fix: Search is not opened on report page with CMD(ctrl) + K
2 parents bd8186e + ca228c4 commit 1493af6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/components/Search/SearchRouter/SearchRouterContext.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import React, {useContext, useMemo, useRef, useState} from 'react';
22
import type {AnimatedTextInputRef} from '@components/RNTextInput';
33
import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute';
4-
import * as Modal from '@userActions/Modal';
4+
import {navigationRef} from '@libs/Navigation/Navigation';
5+
import {close} from '@userActions/Modal';
6+
import NAVIGATORS from '@src/NAVIGATORS';
7+
import SCREENS from '@src/SCREENS';
58
import type ChildrenProps from '@src/types/utils/ChildrenProps';
69

710
type SearchRouterContext = {
@@ -31,7 +34,7 @@ function SearchRouterContextProvider({children}: ChildrenProps) {
3134

3235
const routerContext = useMemo(() => {
3336
const openSearchRouter = () => {
34-
Modal.close(
37+
close(
3538
() => {
3639
setIsSearchRouterDisplayed(true);
3740
searchRouterDisplayedRef.current = true;
@@ -49,7 +52,9 @@ function SearchRouterContextProvider({children}: ChildrenProps) {
4952
// So we need a function that is based on ref to correctly open/close it
5053
// When user is on `/search` page we focus the Input instead of showing router
5154
const toggleSearch = () => {
52-
const isUserOnSearchPage = isSearchTopmostFullScreenRoute();
55+
const searchFullScreenRoutes = navigationRef.getRootState()?.routes.findLast((route) => route.name === NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR);
56+
const lastRoute = searchFullScreenRoutes?.state?.routes?.at(-1);
57+
const isUserOnSearchPage = isSearchTopmostFullScreenRoute() && lastRoute?.name === SCREENS.SEARCH.ROOT;
5358

5459
if (isUserOnSearchPage && searchPageInputRef.current) {
5560
if (searchPageInputRef.current.isFocused()) {

0 commit comments

Comments
 (0)