Skip to content

Commit 8f500dd

Browse files
committed
expose the dragging state and use it as a fallback
1 parent 807c945 commit 8f500dd

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

src/pages/iou/request/step/IOURequestStepScan/index.tsx

+24-22
Original file line numberDiff line numberDiff line change
@@ -654,28 +654,30 @@ function IOURequestStepScan({
654654
shouldShowWrapper={Boolean(backTo)}
655655
testID={IOURequestStepScan.displayName}
656656
>
657-
<View style={[styles.flex1, !Browser.isMobile() && styles.uploadReceiptView(isSmallScreenWidth)]}>
658-
{!isDraggingOver && (Browser.isMobile() ? mobileCameraView() : desktopUploadView())}
659-
<ReceiptDropUI
660-
onDrop={(e) => {
661-
const file = e?.dataTransfer?.files[0];
662-
if (file) {
663-
file.uri = URL.createObjectURL(file);
664-
setReceiptAndNavigate(file);
665-
}
666-
}}
667-
receiptImageTopPosition={receiptImageTopPosition}
668-
/>
669-
<ConfirmModal
670-
title={attachmentInvalidReasonTitle ? translate(attachmentInvalidReasonTitle) : ''}
671-
onConfirm={hideRecieptModal}
672-
onCancel={hideRecieptModal}
673-
isVisible={isAttachmentInvalid}
674-
prompt={attachmentInvalidReason ? translate(attachmentInvalidReason) : ''}
675-
confirmText={translate('common.close')}
676-
shouldShowCancelButton={false}
677-
/>
678-
</View>
657+
{(isDraggingOverWrapper) => (
658+
<View style={[styles.flex1, !Browser.isMobile() && styles.uploadReceiptView(isSmallScreenWidth)]}>
659+
{!(isDraggingOver ?? isDraggingOverWrapper) && (Browser.isMobile() ? mobileCameraView() : desktopUploadView())}
660+
<ReceiptDropUI
661+
onDrop={(e) => {
662+
const file = e?.dataTransfer?.files[0];
663+
if (file) {
664+
file.uri = URL.createObjectURL(file);
665+
setReceiptAndNavigate(file);
666+
}
667+
}}
668+
receiptImageTopPosition={receiptImageTopPosition}
669+
/>
670+
<ConfirmModal
671+
title={attachmentInvalidReasonTitle ? translate(attachmentInvalidReasonTitle) : ''}
672+
onConfirm={hideRecieptModal}
673+
onCancel={hideRecieptModal}
674+
isVisible={isAttachmentInvalid}
675+
prompt={attachmentInvalidReason ? translate(attachmentInvalidReason) : ''}
676+
confirmText={translate('common.close')}
677+
shouldShowCancelButton={false}
678+
/>
679+
</View>
680+
)}
679681
</StepScreenDragAndDropWrapper>
680682
);
681683
}

src/pages/iou/request/step/StepScreenDragAndDropWrapper.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import type {PropsWithChildren} from 'react';
1+
import type {ReactNode} from 'react';
22
import React, {useState} from 'react';
33
import {View} from 'react-native';
44
import DragAndDropProvider from '@components/DragAndDrop/Provider';
55
import HeaderWithBackButton from '@components/HeaderWithBackButton';
66
import ScreenWrapper from '@components/ScreenWrapper';
77
import useThemeStyles from '@hooks/useThemeStyles';
88
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
9+
import callOrReturn from '@src/types/utils/callOrReturn';
910

1011
type StepScreenDragAndDropWrapperProps = {
1112
/** The title to show in the header (should be translated already) */
@@ -22,15 +23,18 @@ type StepScreenDragAndDropWrapperProps = {
2223

2324
/** An ID used for unit testing */
2425
testID: string;
26+
27+
/** The children to render */
28+
children: ((isDraggingOver: boolean) => ReactNode) | ReactNode;
2529
};
2630

27-
function StepScreenDragAndDropWrapper({testID, headerTitle, onBackButtonPress, onEntryTransitionEnd, children, shouldShowWrapper}: PropsWithChildren<StepScreenDragAndDropWrapperProps>) {
31+
function StepScreenDragAndDropWrapper({testID, headerTitle, onBackButtonPress, onEntryTransitionEnd, children, shouldShowWrapper}: StepScreenDragAndDropWrapperProps) {
2832
const styles = useThemeStyles();
2933

3034
const [isDraggingOver, setIsDraggingOver] = useState(false);
3135

3236
if (!shouldShowWrapper) {
33-
return children;
37+
return callOrReturn(children, false);
3438
}
3539

3640
return (
@@ -49,7 +53,7 @@ function StepScreenDragAndDropWrapper({testID, headerTitle, onBackButtonPress, o
4953
title={headerTitle}
5054
onBackButtonPress={onBackButtonPress}
5155
/>
52-
{children}
56+
{callOrReturn(children, isDraggingOver)}
5357
</View>
5458
</DragAndDropProvider>
5559
)}

0 commit comments

Comments
 (0)