diff --git a/src/features/gifPicker/GifPickerDialog.tsx b/src/features/gifPicker/GifPickerDialog.tsx index 08d126b876..b5fd0f4a2e 100644 --- a/src/features/gifPicker/GifPickerDialog.tsx +++ b/src/features/gifPicker/GifPickerDialog.tsx @@ -100,24 +100,21 @@ function GifPickerBody({ const items = isRecentsActive ? getRecents() : networkItems const hasData = items.length > 0 - // Remount the grid only when switching between the network view and the - // local recents list, so FlatList doesn't carry stale virtualized cells - // across that boundary. Within the network view we rely on normal React - // reconciliation as `items` changes — remounting on every search keystroke - // would blur the sticky-header search input. - const viewKey = isRecentsActive ? 'recents' : 'network' - const onEndReached = () => { if (isRecentsActive) return if (isFetchingNextPage || !hasNextPage || error) return void fetchNextPage() } + const onClearSearch = () => { + textInputRef.current?.clear() + setRawSearch('') + setActiveCategory('trending') + } + const onGoBack = () => { if (isSearching || activeCategory !== 'trending') { - textInputRef.current?.clear() - setRawSearch('') - setActiveCategory('trending') + onClearSearch() } else { control.close() } @@ -145,7 +142,8 @@ function GifPickerBody({ 0} onEscape={() => control.close()} /> {showPills && ( @@ -179,7 +177,6 @@ function GifPickerBody({ hasData={hasData} isFetchingNextPage={!isRecentsActive && isFetchingNextPage} error={isRecentsActive ? null : error} - viewKey={viewKey} fetchNextPage={fetchNextPage} onEndReached={onEndReached} onSelectGif={handleSelectGif} diff --git a/src/features/gifPicker/components/GifPickerGrid.tsx b/src/features/gifPicker/components/GifPickerGrid.tsx index 5d3870954e..a2ac8ad0fa 100644 --- a/src/features/gifPicker/components/GifPickerGrid.tsx +++ b/src/features/gifPicker/components/GifPickerGrid.tsx @@ -15,13 +15,6 @@ type Props = { hasData: boolean isFetchingNextPage: boolean error: unknown - /** - * Identifies the current data source at a coarse grain ("recents" vs - * "network"). Used to remount the underlying FlatList when crossing that - * boundary so virtualized cells from the previous view can't bleed into the - * next one. - */ - viewKey: string fetchNextPage: () => Promise onEndReached: () => void onSelectGif: (gif: Gif) => void @@ -35,7 +28,6 @@ export const GifPickerGrid = forwardRef( hasData, isFetchingNextPage, error, - viewKey, fetchNextPage, onEndReached, onSelectGif, @@ -59,7 +51,7 @@ export const GifPickerGrid = forwardRef( return ( ( diff --git a/src/features/gifPicker/components/GifPickerHeader.tsx b/src/features/gifPicker/components/GifPickerHeader.tsx index a3bd34bcad..ab49e8b924 100644 --- a/src/features/gifPicker/components/GifPickerHeader.tsx +++ b/src/features/gifPicker/components/GifPickerHeader.tsx @@ -2,27 +2,27 @@ import {type Ref} from 'react' import {type TextInput, View} from 'react-native' import {useLingui} from '@lingui/react/macro' -import {atoms as a, native, useBreakpoints, useTheme, web} from '#/alf' +import {atoms as a, native, useTheme} from '#/alf' import {Button, ButtonIcon} from '#/components/Button' import * as TextField from '#/components/forms/TextField' -import {ArrowLeft_Stroke2_Corner0_Rounded as Arrow} from '#/components/icons/Arrow' import {MagnifyingGlass_Stroke2_Corner0_Rounded as Search} from '#/components/icons/MagnifyingGlass' -import {IS_WEB} from '#/env' +import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times' export function GifPickerHeader({ inputRef, onChangeText, - onGoBack, + onClear, onEscape, + canClear, }: { inputRef: Ref onChangeText: (text: string) => void - onGoBack: () => void + onClear: () => void onEscape: () => void + canClear: boolean }) { const {t: l} = useLingui() const t = useTheme() - const {gtMobile} = useBreakpoints() return ( - {!gtMobile && IS_WEB && ( - - )} - - + { @@ -62,6 +49,17 @@ export function GifPickerHeader({ } }} /> + {canClear && ( + + )} )