@@ -7,7 +7,7 @@ import React, {
77} from 'react'
88
99import { exploreMessages as messages } from '@audius/common/messages'
10- import { useFocusEffect , useNavigation } from '@react-navigation/native'
10+ import { useNavigation } from '@react-navigation/native'
1111import type { ScrollView } from 'react-native'
1212import { Keyboard } from 'react-native'
1313import { useSafeAreaInsets } from 'react-native-safe-area-context'
@@ -53,27 +53,19 @@ export const SearchExploreHeader = (props: SearchExploreHeaderProps) => {
5353 // eslint-disable-next-line react-hooks/exhaustive-deps
5454 } , [ query ] )
5555
56- useFocusEffect (
57- useCallback ( ( ) => {
58- if ( params ?. autoFocus === true && textInputRef . current ) {
59- textInputRef . current ?. focus ( )
60- }
61- } , [ params ?. autoFocus ] )
62- )
63-
56+ // Focus the search input when navigated here with autoFocus: true (e.g.,
57+ // user taps the search icon). Use a plain useEffect — NOT useFocusEffect —
58+ // so this fires only when the param transitions, not on every screen focus.
59+ // Without this, the keyboard re-appears whenever the app returns from
60+ // background while explore is the active tab. Consume the param by setting
61+ // it back to false so a subsequent search-icon tap can re-trigger focus.
6462 useEffect ( ( ) => {
65- const keyboardDidHideListener = Keyboard . addListener (
66- 'keyboardDidHide' ,
67- ( ) => {
68- if ( params ?. autoFocus === true ) {
69- // @ts -expect-error: setParams is not typed on the generic NavigationProp, but is available on StackNavigationProp
70- navigation . setParams ?.( { autoFocus : false } )
71- }
72- }
73- )
74-
75- return ( ) => keyboardDidHideListener ?. remove ( )
76- } , [ navigation , params ?. autoFocus ] )
63+ if ( params ?. autoFocus === true ) {
64+ textInputRef . current ?. focus ( )
65+ // @ts -expect-error: setParams is not typed on the generic NavigationProp, but is available on StackNavigationProp
66+ navigation . setParams ?.( { autoFocus : false } )
67+ }
68+ } , [ params ?. autoFocus , navigation ] )
7769
7870 const handleOpenLeftNavDrawer = useCallback ( ( ) => {
7971 if ( isNowPlayingDrawerOpen ) return
@@ -117,7 +109,6 @@ export const SearchExploreHeader = (props: SearchExploreHeaderProps) => {
117109 < TextInput
118110 ref = { textInputRef }
119111 label = 'Search'
120- autoFocus = { params ?. autoFocus }
121112 autoCorrect = { false }
122113 placeholder = { messages . searchPlaceholder }
123114 size = { TextInputSize . SMALL }
0 commit comments