Skip to content

Commit 40ab035

Browse files
authored
Merge pull request Expensify#68863 from callstack-internal/fix/unreported-expenses-list
fix: hide show more button, get the data when scrolled to the bottom
2 parents a55cb8c + 692f4d5 commit 40ab035

4 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/components/SelectionList/BaseSelectionList.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ function BaseSelectionList<TItem extends ListItem>({
114114
listHeaderContent,
115115
onEndReached = () => {},
116116
onEndReachedThreshold,
117+
shouldSkipShowMoreButton = false,
117118
windowSize = 5,
118119
updateCellsBatchingPeriod = 50,
119120
removeClippedSubviews = true,
@@ -296,6 +297,12 @@ function BaseSelectionList<TItem extends ListItem>({
296297
}, [customListHeader, customListHeaderHeight, sections, canSelectMultiple, isItemSelected, itemHeights, getItemHeight]);
297298

298299
const [slicedSections, ShowMoreButtonInstance] = useMemo(() => {
300+
if (shouldSkipShowMoreButton) {
301+
// When skipping the Show More button, return all sections without any slicing
302+
const processedSections = getSectionsWithIndexOffset(sections as Array<SectionListDataType<TItem>>);
303+
return [processedSections, null];
304+
}
305+
299306
let remainingOptionsLimit = CONST.MAX_SELECTION_LIST_PAGE_LENGTH * currentPage;
300307
const processedSections = getSectionsWithIndexOffset(
301308
sections.map((section) => {
@@ -322,7 +329,7 @@ function BaseSelectionList<TItem extends ListItem>({
322329
// we don't need to add styles here as they change
323330
// we don't need to add flattenedSections here as they will change along with sections
324331
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
325-
}, [sections, currentPage]);
332+
}, [sections, currentPage, shouldSkipShowMoreButton]);
326333

327334
// Disable `Enter` shortcut if the active element is a button or checkbox
328335
const disableEnterShortcut = activeElementRole && [CONST.ROLE.BUTTON, CONST.ROLE.CHECKBOX].includes(activeElementRole as ButtonOrCheckBoxRoles);

src/components/SelectionList/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,9 @@ type SelectionListProps<TItem extends ListItem> = Partial<ChildrenProps> & {
794794
*/
795795
onEndReachedThreshold?: number;
796796

797+
/** Whether to skip the Show More button pagination logic */
798+
shouldSkipShowMoreButton?: boolean;
799+
797800
/**
798801
* While maxToRenderPerBatch tells the amount of items rendered per batch, setting updateCellsBatchingPeriod tells your VirtualizedList the delay in milliseconds between batch renders (how frequently your component will be rendering the windowed items).
799802
* https://reactnative.dev/docs/optimizing-flatlist-configuration#updatecellsbatchingperiod

src/components/Skeletons/UnreportedExpensesSkeleton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function UnreportedExpensesSkeleton({fixedNumberOfItems}: {fixedNumberOfItems?:
8080

8181
return (
8282
<View
83-
style={[styles.flex1, styles.pt3]}
83+
style={styles.flex1}
8484
ref={containerRef}
8585
>
8686
<ItemListSkeletonView

src/pages/AddUnreportedExpense.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
5050
const [hasMoreUnreportedTransactionsResults] = useOnyx(ONYXKEYS.HAS_MORE_UNREPORTED_TRANSACTIONS_RESULTS, {canBeMissing: true});
5151
const [isLoadingUnreportedTransactions] = useOnyx(ONYXKEYS.IS_LOADING_UNREPORTED_TRANSACTIONS, {canBeMissing: true});
5252
const shouldShowUnreportedTransactionsSkeletons = isLoadingUnreportedTransactions && hasMoreUnreportedTransactionsResults && !isOffline;
53+
5354
function getUnreportedTransactions(transactions: OnyxCollection<Transaction>) {
5455
if (!transactions) {
5556
return [];
@@ -212,6 +213,7 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
212213
}}
213214
onEndReached={fetchMoreUnreportedTransactions}
214215
onEndReachedThreshold={0.75}
216+
shouldSkipShowMoreButton
215217
listFooterContent={shouldShowUnreportedTransactionsSkeletons ? <UnreportedExpensesSkeleton fixedNumberOfItems={3} /> : undefined}
216218
>
217219
{!!errorMessage && (

0 commit comments

Comments
 (0)