Skip to content

Commit

Permalink
Merge pull request #41879 from bernhardoj/fix/40897-text-behind-drag-…
Browse files Browse the repository at this point in the history
…and-drop-instruction-doesnt-hide-when-dragging

Fix the scan receipt instruction still shows when dragging a file over the page
  • Loading branch information
roryabraham authored May 11, 2024
2 parents ada489f + 8f500dd commit c70609b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
46 changes: 24 additions & 22 deletions src/pages/iou/request/step/IOURequestStepScan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -654,28 +654,30 @@ function IOURequestStepScan({
shouldShowWrapper={Boolean(backTo)}
testID={IOURequestStepScan.displayName}
>
<View style={[styles.flex1, !Browser.isMobile() && styles.uploadReceiptView(isSmallScreenWidth)]}>
{!isDraggingOver && (Browser.isMobile() ? mobileCameraView() : desktopUploadView())}
<ReceiptDropUI
onDrop={(e) => {
const file = e?.dataTransfer?.files[0];
if (file) {
file.uri = URL.createObjectURL(file);
setReceiptAndNavigate(file);
}
}}
receiptImageTopPosition={receiptImageTopPosition}
/>
<ConfirmModal
title={attachmentInvalidReasonTitle ? translate(attachmentInvalidReasonTitle) : ''}
onConfirm={hideRecieptModal}
onCancel={hideRecieptModal}
isVisible={isAttachmentInvalid}
prompt={attachmentInvalidReason ? translate(attachmentInvalidReason) : ''}
confirmText={translate('common.close')}
shouldShowCancelButton={false}
/>
</View>
{(isDraggingOverWrapper) => (
<View style={[styles.flex1, !Browser.isMobile() && styles.uploadReceiptView(isSmallScreenWidth)]}>
{!(isDraggingOver ?? isDraggingOverWrapper) && (Browser.isMobile() ? mobileCameraView() : desktopUploadView())}
<ReceiptDropUI
onDrop={(e) => {
const file = e?.dataTransfer?.files[0];
if (file) {
file.uri = URL.createObjectURL(file);
setReceiptAndNavigate(file);
}
}}
receiptImageTopPosition={receiptImageTopPosition}
/>
<ConfirmModal
title={attachmentInvalidReasonTitle ? translate(attachmentInvalidReasonTitle) : ''}
onConfirm={hideRecieptModal}
onCancel={hideRecieptModal}
isVisible={isAttachmentInvalid}
prompt={attachmentInvalidReason ? translate(attachmentInvalidReason) : ''}
confirmText={translate('common.close')}
shouldShowCancelButton={false}
/>
</View>
)}
</StepScreenDragAndDropWrapper>
);
}
Expand Down
12 changes: 8 additions & 4 deletions src/pages/iou/request/step/StepScreenDragAndDropWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type {PropsWithChildren} from 'react';
import type {ReactNode} from 'react';
import React, {useState} from 'react';
import {View} from 'react-native';
import DragAndDropProvider from '@components/DragAndDrop/Provider';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import useThemeStyles from '@hooks/useThemeStyles';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import callOrReturn from '@src/types/utils/callOrReturn';

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

/** An ID used for unit testing */
testID: string;

/** The children to render */
children: ((isDraggingOver: boolean) => ReactNode) | ReactNode;
};

function StepScreenDragAndDropWrapper({testID, headerTitle, onBackButtonPress, onEntryTransitionEnd, children, shouldShowWrapper}: PropsWithChildren<StepScreenDragAndDropWrapperProps>) {
function StepScreenDragAndDropWrapper({testID, headerTitle, onBackButtonPress, onEntryTransitionEnd, children, shouldShowWrapper}: StepScreenDragAndDropWrapperProps) {
const styles = useThemeStyles();

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

if (!shouldShowWrapper) {
return children;
return callOrReturn(children, false);
}

return (
Expand All @@ -49,7 +53,7 @@ function StepScreenDragAndDropWrapper({testID, headerTitle, onBackButtonPress, o
title={headerTitle}
onBackButtonPress={onBackButtonPress}
/>
{children}
{callOrReturn(children, isDraggingOver)}
</View>
</DragAndDropProvider>
)}
Expand Down

0 comments on commit c70609b

Please sign in to comment.