1
1
import React , { useContext , useMemo , useRef , useState } from 'react' ;
2
2
import type { AnimatedTextInputRef } from '@components/RNTextInput' ;
3
3
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' ;
5
8
import type ChildrenProps from '@src/types/utils/ChildrenProps' ;
6
9
7
10
type SearchRouterContext = {
@@ -31,7 +34,7 @@ function SearchRouterContextProvider({children}: ChildrenProps) {
31
34
32
35
const routerContext = useMemo ( ( ) => {
33
36
const openSearchRouter = ( ) => {
34
- Modal . close (
37
+ close (
35
38
( ) => {
36
39
setIsSearchRouterDisplayed ( true ) ;
37
40
searchRouterDisplayedRef . current = true ;
@@ -49,7 +52,9 @@ function SearchRouterContextProvider({children}: ChildrenProps) {
49
52
// So we need a function that is based on ref to correctly open/close it
50
53
// When user is on `/search` page we focus the Input instead of showing router
51
54
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 ;
53
58
54
59
if ( isUserOnSearchPage && searchPageInputRef . current ) {
55
60
if ( searchPageInputRef . current . isFocused ( ) ) {
0 commit comments