Skip to content

Commit f950823

Browse files
dylanjeffersclaude
andauthored
fix(mobile): stop cold-launch keyboard flash on explore search (#14395)
## Summary - Follow-up to [apps#14289](#14289). That PR stopped the keyboard from re-appearing on background→foreground, but a brief keyboard flash still happened on app **cold launch**. - Root cause: the explore screen's `useEffect` calls `.focus()` whenever `params?.autoFocus === true`, regardless of whether the explore tab is the active tab. If the explore screen mounts off-screen with a stale `autoFocus: true` on its route, the focus call fires anyway and briefly summons the keyboard. - Fix: gate the focus call on `useIsFocused()` so the param is only consumed while the explore tab is actually the active tab. The intentional search-icon-tap flow still works — navigating to explore puts the tab in focus before the effect runs. ## Test plan - [ ] Cold-start the app → no keyboard flash on initial load (regardless of which tab was last active before the kill) - [ ] Tap search icon from any tab header → explore opens with keyboard up and input focused - [ ] On explore, dismiss keyboard, switch to another tab, return to explore → keyboard does NOT reappear - [ ] On explore with keyboard up, background the app, return from background → keyboard does NOT reappear (still works after this change) - [ ] Tap search icon → keyboard reappears, dismiss it, tap search icon again → keyboard reappears (param re-trigger still works) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 57bf817 commit f950823

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

packages/mobile/src/screens/explore-screen/components/SearchExploreHeader.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React, {
77
} from 'react'
88

99
import { exploreMessages as messages } from '@audius/common/messages'
10-
import { useNavigation } from '@react-navigation/native'
10+
import { useIsFocused, useNavigation } from '@react-navigation/native'
1111
import type { ScrollView } from 'react-native'
1212
import { Keyboard } from 'react-native'
1313
import { useSafeAreaInsets } from 'react-native-safe-area-context'
@@ -40,6 +40,7 @@ export const SearchExploreHeader = (props: SearchExploreHeaderProps) => {
4040
const { params } = useExploreRoute<'SearchExplore'>()
4141
const { drawerHelpers } = useContext(AppDrawerContext)
4242
const navigation = useNavigation()
43+
const isFocused = useIsFocused()
4344
const { isOpen: isNowPlayingDrawerOpen } = useDrawer('NowPlaying')
4445
const textInputRef = useRef<any>(null)
4546

@@ -59,13 +60,18 @@ export const SearchExploreHeader = (props: SearchExploreHeaderProps) => {
5960
// Without this, the keyboard re-appears whenever the app returns from
6061
// background while explore is the active tab. Consume the param by setting
6162
// it back to false so a subsequent search-icon tap can re-trigger focus.
63+
//
64+
// Gate on isFocused so a stale autoFocus param can't summon the keyboard
65+
// while the explore tab isn't the active tab — this is what caused the
66+
// brief keyboard flash on cold launch when the explore screen mounted
67+
// off-screen with autoFocus: true already on its route.
6268
useEffect(() => {
63-
if (params?.autoFocus === true) {
69+
if (params?.autoFocus === true && isFocused) {
6470
textInputRef.current?.focus()
6571
// @ts-expect-error: setParams is not typed on the generic NavigationProp, but is available on StackNavigationProp
6672
navigation.setParams?.({ autoFocus: false })
6773
}
68-
}, [params?.autoFocus, navigation])
74+
}, [params?.autoFocus, navigation, isFocused])
6975

7076
const handleOpenLeftNavDrawer = useCallback(() => {
7177
if (isNowPlayingDrawerOpen) return

0 commit comments

Comments
 (0)