|
1 | 1 | import {PortalHost} from '@gorhom/portal'; |
2 | 2 | import React, {useCallback, useMemo} from 'react'; |
3 | | -import {InteractionManager, View} from 'react-native'; |
| 3 | +// We use Animated for all functionality related to wide RHP to make it easier |
| 4 | +// to interact with react-navigation components (e.g., CardContainer, interpolator), which also use Animated. |
| 5 | +// eslint-disable-next-line no-restricted-imports |
| 6 | +import {Animated, InteractionManager, ScrollView, View} from 'react-native'; |
4 | 7 | import type {OnyxEntry} from 'react-native-onyx'; |
5 | 8 | import HeaderGap from '@components/HeaderGap'; |
6 | 9 | import MoneyReportHeader from '@components/MoneyReportHeader'; |
7 | 10 | import MoneyRequestHeader from '@components/MoneyRequestHeader'; |
8 | 11 | import OfflineWithFeedback from '@components/OfflineWithFeedback'; |
| 12 | +import MoneyRequestReceiptView from '@components/ReportActionItem/MoneyRequestReceiptView'; |
9 | 13 | import ReportActionsSkeletonView from '@components/ReportActionsSkeletonView'; |
10 | 14 | import ReportHeaderSkeletonView from '@components/ReportHeaderSkeletonView'; |
11 | 15 | import useNetwork from '@hooks/useNetwork'; |
12 | 16 | import useNewTransactions from '@hooks/useNewTransactions'; |
13 | 17 | import useOnyx from '@hooks/useOnyx'; |
14 | 18 | import usePaginatedReportActions from '@hooks/usePaginatedReportActions'; |
15 | 19 | import useParentReportAction from '@hooks/useParentReportAction'; |
| 20 | +import useResponsiveLayout from '@hooks/useResponsiveLayout'; |
16 | 21 | import useThemeStyles from '@hooks/useThemeStyles'; |
17 | 22 | import useTransactionsAndViolationsForReport from '@hooks/useTransactionsAndViolationsForReport'; |
18 | 23 | import {removeFailedReport} from '@libs/actions/Report'; |
@@ -56,6 +61,16 @@ function goBackFromSearchMoneyRequest() { |
56 | 61 | const rootState = navigationRef.getRootState(); |
57 | 62 | const lastRoute = rootState.routes.at(-1); |
58 | 63 |
|
| 64 | + if (!lastRoute) { |
| 65 | + Log.hmmm('[goBackFromSearchMoneyRequest()] No last route found in root state.'); |
| 66 | + return; |
| 67 | + } |
| 68 | + |
| 69 | + if (lastRoute?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR) { |
| 70 | + Navigation.goBack(); |
| 71 | + return; |
| 72 | + } |
| 73 | + |
59 | 74 | if (lastRoute?.name !== NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR) { |
60 | 75 | Log.hmmm('[goBackFromSearchMoneyRequest()] goBackFromSearchMoneyRequest was called from a different navigator than SearchFullscreenNavigator.'); |
61 | 76 | return; |
@@ -84,6 +99,10 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe |
84 | 99 | const styles = useThemeStyles(); |
85 | 100 | const {isOffline} = useNetwork(); |
86 | 101 |
|
| 102 | + // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth |
| 103 | + const {isSmallScreenWidth} = useResponsiveLayout(); |
| 104 | + |
| 105 | + const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: false}); |
87 | 106 | const reportID = report?.reportID; |
88 | 107 | const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true}); |
89 | 108 | const [isComposerFullSize = false] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportID}`, {canBeMissing: true}); |
@@ -129,6 +148,9 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe |
129 | 148 | const isEmptyTransactionReport = visibleTransactions && visibleTransactions.length === 0 && transactionThreadReportID === undefined; |
130 | 149 | const shouldDisplayMoneyRequestActionsList = !!isEmptyTransactionReport || shouldDisplayReportTableView(report, visibleTransactions ?? []); |
131 | 150 |
|
| 151 | + const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, {canBeMissing: true}); |
| 152 | + const shouldShowWideRHPReceipt = visibleTransactions.length === 1 && !isSmallScreenWidth && !!transactionThreadReport; |
| 153 | + |
132 | 154 | const reportHeaderView = useMemo( |
133 | 155 | () => |
134 | 156 | isTransactionThreadView ? ( |
@@ -211,47 +233,61 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe |
211 | 233 | > |
212 | 234 | <HeaderGap /> |
213 | 235 | {reportHeaderView} |
214 | | - <View style={[styles.overflowHidden, styles.justifyContentEnd, styles.flex1]}> |
215 | | - {shouldDisplayMoneyRequestActionsList ? ( |
216 | | - <MoneyRequestReportActionsList |
217 | | - report={report} |
218 | | - policy={policy} |
219 | | - transactions={visibleTransactions} |
220 | | - hasPendingDeletionTransaction={hasPendingDeletionTransaction} |
221 | | - newTransactions={newTransactions} |
222 | | - reportActions={reportActions} |
223 | | - violations={allReportViolations} |
224 | | - hasOlderActions={hasOlderActions} |
225 | | - hasNewerActions={hasNewerActions} |
226 | | - showReportActionsLoadingState={isLoadingInitialReportActions && !reportMetadata?.hasOnceLoadedReportActions} |
227 | | - /> |
228 | | - ) : ( |
229 | | - <ReportActionsView |
230 | | - report={report} |
231 | | - reportActions={reportActions} |
232 | | - isLoadingInitialReportActions={reportMetadata?.isLoadingInitialReportActions} |
233 | | - hasNewerActions={hasNewerActions} |
234 | | - hasOlderActions={hasOlderActions} |
235 | | - parentReportAction={parentReportAction} |
236 | | - transactionThreadReportID={transactionThreadReportID} |
237 | | - /> |
| 236 | + <View style={[styles.flex1, styles.flexRow]}> |
| 237 | + {shouldShowWideRHPReceipt && ( |
| 238 | + <Animated.View style={styles.wideRHPMoneyRequestReceiptViewContainer}> |
| 239 | + <ScrollView contentContainerStyle={styles.wideRHPMoneyRequestReceiptViewScrollViewContainer}> |
| 240 | + <MoneyRequestReceiptView |
| 241 | + allReports={allReports} |
| 242 | + report={transactionThreadReport} |
| 243 | + fillSpace |
| 244 | + isDisplayedInWideRHP |
| 245 | + /> |
| 246 | + </ScrollView> |
| 247 | + </Animated.View> |
238 | 248 | )} |
239 | | - {shouldDisplayReportFooter ? ( |
240 | | - <> |
241 | | - <ReportFooter |
| 249 | + <View style={[[styles.flex1, styles.justifyContentEnd, styles.overflowHidden]]}> |
| 250 | + {shouldDisplayMoneyRequestActionsList ? ( |
| 251 | + <MoneyRequestReportActionsList |
242 | 252 | report={report} |
243 | | - reportMetadata={reportMetadata} |
244 | 253 | policy={policy} |
245 | | - pendingAction={reportPendingAction} |
246 | | - isComposerFullSize={!!isComposerFullSize} |
247 | | - lastReportAction={lastReportAction} |
248 | | - reportTransactions={transactions} |
249 | | - // If the report is from the 'Send Money' flow, we add the comment to the `iou` report because for these we don't combine reportActions even if there is a single transaction (they always have a single transaction) |
250 | | - transactionThreadReportID={isSentMoneyReport ? undefined : transactionThreadReportID} |
| 254 | + transactions={visibleTransactions} |
| 255 | + hasPendingDeletionTransaction={hasPendingDeletionTransaction} |
| 256 | + newTransactions={newTransactions} |
| 257 | + reportActions={reportActions} |
| 258 | + violations={allReportViolations} |
| 259 | + hasOlderActions={hasOlderActions} |
| 260 | + hasNewerActions={hasNewerActions} |
| 261 | + showReportActionsLoadingState={isLoadingInitialReportActions && !reportMetadata?.hasOnceLoadedReportActions} |
| 262 | + /> |
| 263 | + ) : ( |
| 264 | + <ReportActionsView |
| 265 | + report={report} |
| 266 | + reportActions={reportActions} |
| 267 | + isLoadingInitialReportActions={reportMetadata?.isLoadingInitialReportActions} |
| 268 | + hasNewerActions={hasNewerActions} |
| 269 | + hasOlderActions={hasOlderActions} |
| 270 | + parentReportAction={parentReportAction} |
| 271 | + transactionThreadReportID={transactionThreadReportID} |
251 | 272 | /> |
252 | | - <PortalHost name="suggestions" /> |
253 | | - </> |
254 | | - ) : null} |
| 273 | + )} |
| 274 | + {shouldDisplayReportFooter ? ( |
| 275 | + <> |
| 276 | + <ReportFooter |
| 277 | + report={report} |
| 278 | + reportMetadata={reportMetadata} |
| 279 | + policy={policy} |
| 280 | + pendingAction={reportPendingAction} |
| 281 | + isComposerFullSize={!!isComposerFullSize} |
| 282 | + lastReportAction={lastReportAction} |
| 283 | + reportTransactions={transactions} |
| 284 | + // If the report is from the 'Send Money' flow, we add the comment to the `iou` report because for these we don't combine reportActions even if there is a single transaction (they always have a single transaction) |
| 285 | + transactionThreadReportID={isSentMoneyReport ? undefined : transactionThreadReportID} |
| 286 | + /> |
| 287 | + <PortalHost name="suggestions" /> |
| 288 | + </> |
| 289 | + ) : null} |
| 290 | + </View> |
255 | 291 | </View> |
256 | 292 | </OfflineWithFeedback> |
257 | 293 | </View> |
|
0 commit comments