Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,21 @@ function MoneyRequestReportPreviewContent({
// undefined makes arrow buttons react on currentIndex changes when scrolling manually
const [optimisticIndex, setOptimisticIndex] = useState<number | undefined>(undefined);
const carouselRef = useRef<FlashListRef<Transaction> | null>(null);
const prevTransactionCountForScroll = useRef(carouselTransactions.length);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see we have this ref prevCarouselTransactionLength that does the same ... can it be used instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abzokhattab i think they serve different purposes. prevCarouselTransactionLength starts at 0 and updates in the cleanup of its effect, while prevTransactionCountForScroll starts at carouselTransactions.length and updates at the end of its effect.

const [carouselKey, setCarouselKey] = useState(0);

// 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) {
setCurrentIndex(0);
setOptimisticIndex(undefined);
setCarouselKey((prev) => prev + 1);
}
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;
Expand Down Expand Up @@ -970,6 +985,7 @@ function MoneyRequestReportPreviewContent({
) : (
<View style={[styles.flex1, styles.flexColumn, styles.overflowVisible, styles.minHeight42]}>
<FlashList
key={carouselKey}
snapToAlignment="start"
decelerationRate="fast"
snapToOffsets={snapOffsets}
Expand Down
Loading