From cb86c85f08a5d56a027860c5364bae68533253cf Mon Sep 17 00:00:00 2001 From: Taras Perun Date: Wed, 20 Mar 2024 21:17:28 +0100 Subject: [PATCH] update listID --- src/libs/NumberUtils.ts | 10 +++++++++- src/libs/ReportActionsUtils.ts | 6 ------ src/pages/home/report/ReportActionsView.tsx | 8 +++++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/libs/NumberUtils.ts b/src/libs/NumberUtils.ts index 62d6fa00906a..2dfc1e722c58 100644 --- a/src/libs/NumberUtils.ts +++ b/src/libs/NumberUtils.ts @@ -92,4 +92,12 @@ function clamp(value: number, min: number, max: number): number { return Math.min(Math.max(value, min), max); } -export {rand64, generateHexadecimalValue, generateRandomInt, parseFloatAnyLocale, roundDownToLargestMultiple, roundToTwoDecimalPlaces, clamp}; +function generateNewRandomInt(old: number, min: number, max: number): number { + let newNum = old; + while (newNum === old) { + newNum = generateRandomInt(min, max); + } + return newNum; +} + +export {rand64, generateHexadecimalValue, generateRandomInt, parseFloatAnyLocale, roundDownToLargestMultiple, roundToTwoDecimalPlaces, clamp, generateNewRandomInt}; diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 8678d10d3f89..f069bcfa58ae 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1,16 +1,11 @@ -import type {RouteProp} from '@react-navigation/native'; import fastMerge from 'expensify-common/lib/fastMerge'; import _ from 'lodash'; import lodashFindLast from 'lodash/findLast'; -import {useCallback, useLayoutEffect, useMemo, useRef, useState} from 'react'; import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; -import getInitialPaginationSize from '@pages/home/report/getInitialPaginationSize'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type SCREENS from '@src/SCREENS'; -import type * as OnyxTypes from '@src/types/onyx'; import type { ActionName, ChangeLog, @@ -31,7 +26,6 @@ import isReportMessageAttachment from './isReportMessageAttachment'; import * as Localize from './Localize'; import Log from './Log'; import type {MessageElementBase, MessageTextElement} from './MessageElement'; -import type {CentralPaneNavigatorParamList} from './Navigation/types'; import * as PersonalDetailsUtils from './PersonalDetailsUtils'; import type {OptimisticIOUReportAction} from './ReportUtils'; diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 970c8c970f8f..520a9a3604c5 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -12,6 +12,7 @@ import usePrevious from '@hooks/usePrevious'; import useWindowDimensions from '@hooks/useWindowDimensions'; import getIsReportFullyVisible from '@libs/getIsReportFullyVisible'; import type {CentralPaneNavigatorParamList} from '@libs/Navigation/types'; +import {generateNewRandomInt} from '@libs/NumberUtils'; import Performance from '@libs/Performance'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import {isUserCreatedPolicyRoom} from '@libs/ReportUtils'; @@ -59,7 +60,7 @@ type ReportActionsViewProps = ReportActionsViewOnyxProps & { const DIFF_BETWEEN_SCREEN_HEIGHT_AND_LIST = 120; const SPACER = 16; -let listIDCount = Math.round(Math.random() * 100); +let listOldID = Math.round(Math.random() * 100); function ReportActionsView({ report, @@ -127,8 +128,9 @@ function ReportActionsView({ const listID = useMemo(() => { isFirstLinkedActionRender.current = true; - listIDCount += 1; - return listIDCount; + const newID = generateNewRandomInt(listOldID, 1, Number.MAX_SAFE_INTEGER); + listOldID = newID; + return newID; // eslint-disable-next-line react-hooks/exhaustive-deps }, [route, isLoadingInitialReportActions]);