From 6fb3124c7c60c4f01f76ab0f7453d2d8cd415891 Mon Sep 17 00:00:00 2001 From: thelullabyy Date: Tue, 2 Dec 2025 00:32:00 +0800 Subject: [PATCH 1/4] fix: empty space issue --- .../SearchPageHeader/SearchFiltersBar.tsx | 92 ++++++++++++++----- 1 file changed, 67 insertions(+), 25 deletions(-) diff --git a/src/components/Search/SearchPageHeader/SearchFiltersBar.tsx b/src/components/Search/SearchPageHeader/SearchFiltersBar.tsx index 31a00010f629..8c6b1ac0ff72 100644 --- a/src/components/Search/SearchPageHeader/SearchFiltersBar.tsx +++ b/src/components/Search/SearchPageHeader/SearchFiltersBar.tsx @@ -4,7 +4,7 @@ import {emailSelector} from '@selectors/Session'; import {searchResultsErrorSelector} from '@selectors/Snapshot'; import React, {useCallback, useContext, useEffect, useMemo, useRef} from 'react'; import type {ReactNode} from 'react'; -import {View} from 'react-native'; +import {FlatList, View} from 'react-native'; // eslint-disable-next-line no-restricted-imports import type {ScrollView as RNScrollView} from 'react-native'; import Button from '@components/Button'; @@ -48,6 +48,7 @@ import {getActiveAdminWorkspaces, getAllTaxRates, isPaidGroupPolicy} from '@libs import {isExpenseReport} from '@libs/ReportUtils'; import {buildFilterFormValuesFromQuery, buildQueryStringFromFilterFormValues, isFilterSupported, isSearchDatePreset} from '@libs/SearchQueryUtils'; import {getDatePresets, getFeedOptions, getGroupByOptions, getGroupCurrencyOptions, getHasOptions, getStatusOptions, getTypeOptions, getWithdrawalTypeOptions} from '@libs/SearchUIUtils'; +import shouldAdjustScroll from '@libs/shouldAdjustScroll'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -86,7 +87,7 @@ function SearchFiltersBar({ latestBankItems, }: SearchFiltersBarProps) { const isFocused = useIsFocused(); - const scrollRef = useRef(null); + const scrollRef = useRef>(null); const currentPolicy = usePolicy(currentSelectedPolicyID); const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isUserValidatedSelector, canBeMissing: true}); // type, groupBy and status values are not guaranteed to respect the ts type as they come from user input @@ -733,6 +734,62 @@ function SearchFiltersBar({ return filterFormValues[key as SearchAdvancedFiltersKey]; }); }, [filterFormValues, filters, typeFiltersKeys]); + const prevFiltersLength = useRef(0); + + useEffect(() => { + return () => { + prevFiltersLength.current = filters.length; + }; + }, [filters.length]); + + const adjustScroll = useCallback( + (e) => { + // Workaround for a known React Native bug on Android (https://github.com/facebook/react-native/issues/27504): + // When the FlatList is scrolled to the end and the last item is deleted, a blank space is left behind. + // To fix this, we detect when onEndReached is triggered due to an item deletion, + // and programmatically scroll to the end to fill the space. + if (!shouldAdjustScroll || e.distanceFromEnd > 0) { + return; + } + prevFiltersLength.current = filtersFlatLength; + scrollRef.current?.scrollToEnd(); + }, + [filtersFlatLength], + ); + + const renderFilterItem = useCallback( + // eslint-disable-next-line react/no-unused-prop-types + ({item}: {item: FilterItem}) => ( + + ), + [], + ); + + const filterButtonText = useMemo( + () => translate('search.filtersHeader') + (hiddenSelectedFilters.length > 0 ? ` (${hiddenSelectedFilters.length})` : ''), + [translate, hiddenSelectedFilters.length], + ); + + const renderListFooter = useCallback( + () => ( +