|
1 | | -import React, {useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react'; |
| 1 | +import React, {useCallback, useContext, useDeferredValue, useEffect, useMemo, useRef, useState} from 'react'; |
2 | 2 | import {ActivityIndicator, FlatList, View} from 'react-native'; |
3 | 3 | import type {LayoutChangeEvent, ListRenderItemInfo, ViewToken} from 'react-native'; |
4 | 4 | import Animated, {useAnimatedStyle, useSharedValue, withDelay, withSpring, withTiming} from 'react-native-reanimated'; |
@@ -115,6 +115,11 @@ function MoneyRequestReportPreviewContent({ |
115 | 115 | shouldShowBorder = false, |
116 | 116 | onPress, |
117 | 117 | }: MoneyRequestReportPreviewContentProps) { |
| 118 | + const [chatReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${chatReportID}`, {canBeMissing: true, allowStaleData: true}); |
| 119 | + const shouldShowLoading = !chatReportMetadata?.hasOnceLoadedReportActions && transactions.length === 0; |
| 120 | + // `hasOnceLoadedReportActions` becomes true before transactions populate fully, |
| 121 | + // so we defer the loading state update to ensure transactions are loaded |
| 122 | + const shouldShowLoadingDeferred = useDeferredValue(shouldShowLoading); |
118 | 123 | const lastTransaction = transactions?.at(0); |
119 | 124 | const shouldShowEmptyPlaceholder = transactions.length === 0; |
120 | 125 | const theme = useTheme(); |
@@ -408,7 +413,7 @@ function MoneyRequestReportPreviewContent({ |
408 | 413 |
|
409 | 414 | // The button should expand up to transaction width |
410 | 415 | const buttonMaxWidth = |
411 | | - !shouldUseNarrowLayout && reportPreviewStyles.transactionPreviewCarouselStyle.width >= CONST.REPORT.TRANSACTION_PREVIEW.CAROUSEL.WIDE_WIDTH |
| 416 | + !shouldUseNarrowLayout && reportPreviewStyles.transactionPreviewCarouselStyle.width >= CONST.REPORT.TRANSACTION_PREVIEW.CAROUSEL.MIN_WIDE_WIDTH |
412 | 417 | ? {maxWidth: reportPreviewStyles.transactionPreviewCarouselStyle.width} |
413 | 418 | : {}; |
414 | 419 |
|
@@ -707,11 +712,14 @@ function MoneyRequestReportPreviewContent({ |
707 | 712 | )} |
708 | 713 | </View> |
709 | 714 | </View> |
710 | | - {!currentWidth ? ( |
| 715 | + {!currentWidth || shouldShowLoading || shouldShowLoadingDeferred ? ( |
711 | 716 | <View |
712 | 717 | style={[ |
713 | 718 | { |
714 | 719 | height: CONST.REPORT.TRANSACTION_PREVIEW.CAROUSEL.WIDE_HEIGHT, |
| 720 | + minWidth: shouldUseNarrowLayout |
| 721 | + ? CONST.REPORT.TRANSACTION_PREVIEW.CAROUSEL.MIN_NARROW_WIDTH |
| 722 | + : CONST.REPORT.TRANSACTION_PREVIEW.CAROUSEL.MIN_WIDE_WIDTH, |
715 | 723 | }, |
716 | 724 | styles.justifyContentCenter, |
717 | 725 | styles.mtn1, |
|
0 commit comments