From b1b87197af19457cd1ea4a2d4e8d3512dfb6e759 Mon Sep 17 00:00:00 2001 From: daledah Date: Wed, 7 Jan 2026 12:42:43 +0700 Subject: [PATCH 1/3] fix: preview is displayed cutted off when adding expense --- .../MoneyRequestReportPreviewContent.tsx | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx index 73ff38b44d69..1f600571d941 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx @@ -466,6 +466,34 @@ function MoneyRequestReportPreviewContent({ carouselTransactionsRef.current = carouselTransactions; }, [carouselTransactions]); + useEffect(() => { + const prevLength = prevCarouselTransactionLength.current; + const currentLength = carouselTransactions.length; + + // Reset to beginning if currentIndex is out of bounds for the new transactions list + if (currentIndex > 0 && (currentLength === 0 || currentIndex >= currentLength)) { + setCurrentIndex(0); + setOptimisticIndex(undefined); + setCurrentVisibleItems([0]); + // Scroll the FlatList back to the beginning + if (carouselRef.current && currentLength > 0) { + carouselRef.current.scrollToIndex({index: 0, animated: false}); + } else if (carouselRef.current) { + // If there are no transactions, scroll to offset 0 + carouselRef.current.scrollToOffset({offset: 0, animated: false}); + } + } + // Reset when transactions go from empty to having items (to ensure we start at the beginning) + else if (prevLength === 0 && currentLength > 0 && currentIndex !== 0) { + setCurrentIndex(0); + setOptimisticIndex(undefined); + setCurrentVisibleItems([0]); + if (carouselRef.current) { + carouselRef.current.scrollToIndex({index: 0, animated: false}); + } + } + }, [carouselTransactions.length, currentIndex]); + useFocusEffect( useCallback(() => { const index = carouselTransactions.findIndex((transaction) => newTransactionIDs?.includes(transaction.transactionID)); From 0aede45dfff408eb906c41e782ca730699e2be54 Mon Sep 17 00:00:00 2001 From: daledah Date: Tue, 24 Feb 2026 14:49:14 +0700 Subject: [PATCH 2/3] add useEffect to reset current index --- .../MoneyRequestReportPreviewContent.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx index f66b0bfc79d9..e315f553b605 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx @@ -465,6 +465,20 @@ function MoneyRequestReportPreviewContent({ // undefined makes arrow buttons react on currentIndex changes when scrolling manually const [optimisticIndex, setOptimisticIndex] = useState(undefined); const carouselRef = useRef | null>(null); + const prevTransactionCountForScroll = useRef(carouselTransactions.length); + + // Reset carousel scroll position when transitioning from empty to non-empty data. + // Without this, a stale scroll offset from a previous state (e.g., after moving all + // expenses out) causes the newly added transaction preview to render off-screen. + useEffect(() => { + if (carouselTransactions.length > 0 && prevTransactionCountForScroll.current === 0) { + carouselRef.current?.scrollToOffset({offset: 0, animated: false}); + setCurrentIndex(0); + setOptimisticIndex(undefined); + } + prevTransactionCountForScroll.current = carouselTransactions.length; + }, [carouselTransactions.length]); + const visibleItemsOnEndCount = useMemo(() => { const lastItemWidth = transactions.length > MAX_PREVIEWS_NUMBER ? footerWidth : reportPreviewStyles.transactionPreviewCarouselStyle.width; const lastItemWithGap = lastItemWidth + styles.gap2.gap; From 5bfb0e47611fc75acfd926992c61b1ce436e1fde Mon Sep 17 00:00:00 2001 From: daledah Date: Mon, 2 Mar 2026 11:20:43 +0700 Subject: [PATCH 3/3] Use key to rerender flatlist --- .../MoneyRequestReportPreviewContent.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx index 0ca0fa95e8f6..8c3dd734b394 100644 --- a/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx +++ b/src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx @@ -474,15 +474,16 @@ function MoneyRequestReportPreviewContent({ const [optimisticIndex, setOptimisticIndex] = useState(undefined); const carouselRef = useRef | null>(null); const prevTransactionCountForScroll = useRef(carouselTransactions.length); + const [carouselKey, setCarouselKey] = useState(0); - // Reset carousel scroll position when transitioning from empty to non-empty data. - // Without this, a stale scroll offset from a previous state (e.g., after moving all - // expenses out) causes the newly added transaction preview to render off-screen. + // Reset carousel when transitioning from empty to non-empty data. + // scrollToOffset doesn't clear RecyclerListView's internal layout cache on iOS mobile web, + // so we force a full re-mount via key to prevent new items from rendering off-screen. useEffect(() => { if (carouselTransactions.length > 0 && prevTransactionCountForScroll.current === 0) { - carouselRef.current?.scrollToOffset({offset: 0, animated: false}); setCurrentIndex(0); setOptimisticIndex(undefined); + setCarouselKey((prev) => prev + 1); } prevTransactionCountForScroll.current = carouselTransactions.length; }, [carouselTransactions.length]); @@ -930,6 +931,7 @@ function MoneyRequestReportPreviewContent({ ) : (