Skip to content

Commit

Permalink
fix: race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
MounirDhahri committed Dec 12, 2024
1 parent 79bb158 commit b972158
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/app/Components/GlobalSearchInput/GlobalSearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Flex, RoundSearchInput, Touchable } from "@artsy/palette-mobile"
import { GlobalSearchInputOverlay } from "app/Components/GlobalSearchInput/GlobalSearchInputOverlay"
import { useDismissSearchOverlayOnTabBarPress } from "app/Components/GlobalSearchInput/utils/useDismissSearchOverlayOnTabBarPress"
import { ICON_HIT_SLOP } from "app/Components/constants"
import { useDebouncedValue } from "app/utils/hooks/useDebouncedValue"
import { forwardRef, Fragment, useImperativeHandle, useState } from "react"
import { useTracking } from "react-tracking"

Expand All @@ -16,13 +17,14 @@ export type GlobalSearchInput = {
export const GlobalSearchInput = forwardRef<GlobalSearchInput, GlobalSearchInputProps>(
({ ownerType }, ref) => {
const [isVisible, setIsVisible] = useState(false)
const debouncedIsVisible = useDebouncedValue({ value: isVisible })
const tracking = useTracking()

useDismissSearchOverlayOnTabBarPress({ isVisible, ownerType, setIsVisible })

useImperativeHandle(ref, () => ({
focus: () => {
if (!isVisible) {
if (!debouncedIsVisible.debouncedValue) {
setIsVisible(true)
}
},
Expand Down
3 changes: 1 addition & 2 deletions src/app/Scenes/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ export const Search: React.FC = () => {

useRefetchWhenQueryChanged({ query: searchQuery, refetch })

// Focus input and open keyboard on bottom nav Search tab double-tab
const scrollableRef = useBottomTabsScrollToTop(() => {
if (enableNewSearchModal) {
// Focus input and open keyboard on bottom nav Search tab double-tab
searchInputRef.current?.focus()
} else {
// Focus input and open keyboard on bottom nav Search tab double-tab
searchProviderValues.inputRef.current?.focus()
}
})
Expand Down

0 comments on commit b972158

Please sign in to comment.