-
Notifications
You must be signed in to change notification settings - Fork 3.6k
refactor: IOURequestStepScan clean-up, phase 3: Consolidate isMobile() and add useDragAndDropSupport
#83380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
roryabraham
merged 33 commits into
Expensify:main
from
samranahm:79929/IOURequestStepScan-clean-up-p3
Mar 13, 2026
Merged
refactor: IOURequestStepScan clean-up, phase 3: Consolidate isMobile() and add useDragAndDropSupport
#83380
Changes from 18 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
63f573d
Add useDragAndDropSupport hook for native and web environment
samranahm 6b6563c
Refactor IOURequestStepScan to use isMobileWeb and canUseDragAndDrop
samranahm 0490ef1
fix prettier
samranahm ffcdcf5
remove useDragAndDropSupport hook
samranahm 711c503
remove isMobileWeb from mobileCameraView since we only show this if i…
samranahm e07e6d5
Merge remote-tracking branch 'upstream/main' into 79929/IOURequestSte…
samranahm 3866b79
Add DesktopWebUploadView and MobileWebCameraView components
samranahm e3c6c50
Refactor IOURequestStepScan component to use MobileWebCameraView and …
samranahm 79a1b74
Merge remote-tracking branch 'upstream/main' into 79929/IOURequestSte…
samranahm 21cba79
update dir for IOURequestStepScan
samranahm bd15189
refactor: consolidate IOURequestStepScan components and hooks
samranahm 6921d17
Merge remote-tracking branch 'upstream/main' into 79929/IOURequestSte…
samranahm 3d3966d
Merge remote-tracking branch 'upstream/main' into 79929/IOURequestSte…
samranahm 5f632c1
Merge remote-tracking branch 'upstream/main' into 79929/IOURequestSte…
samranahm 763fe54
move screen wrapper to each platform component
samranahm eb16fb9
Refactor receipt scanning logic to streamline mobile and web components.
samranahm 73b696e
move useMobileReceiptScan test to seprate file
samranahm 49b5b44
prettier
samranahm 839ffad
Add isDraggingOverWrapper from useDragAndDropState in DesktopWebUploa…
samranahm c7cdc51
add UseMobileReceiptScanParams type
samranahm c29310e
Move LocationPermissionFlowSelector to Selectors
samranahm 36d8ac9
reafactor the hooks to pass required params only
samranahm cd58af9
updated test to remove createMockReceiptScan mock
samranahm 6c8a190
lint
samranahm 8b126c2
Merge remote-tracking branch 'upstream/main' into 79929/IOURequestSte…
samranahm bef83fd
Merge remote-tracking branch 'upstream/main' into 79929/IOURequestSte…
samranahm f1e0dc2
Merge remote-tracking branch 'upstream/main' into 79929/IOURequestSte…
samranahm feabace
Refactor IOURequestStepScan components and hooks for clarity
samranahm 9f39222
Merge branch 'Expensify:main' into 79929/IOURequestStepScan-clean-up-p3
samranahm c8be9a4
Merge remote-tracking branch 'upstream/main' into 79929/IOURequestSte…
samranahm 19ad53a
Merge remote-tracking branch 'upstream/main' into 79929/IOURequestSte…
samranahm df59882
Refactor camera permission handling in MobileWebCameraView
samranahm a41cc41
Update lint script to reduce max warnings from 334 to 316
samranahm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
src/pages/iou/request/step/IOURequestStepScan/components/DesktopWebUploadView.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| import React, {useRef, useState} from 'react'; | ||
| import {PanResponder, View} from 'react-native'; | ||
| import AttachmentPicker from '@components/AttachmentPicker'; | ||
| import Button from '@components/Button'; | ||
| import DragAndDropConsumer from '@components/DragAndDrop/Consumer'; | ||
| import DropZoneUI from '@components/DropZone/DropZoneUI'; | ||
| import Icon from '@components/Icon'; | ||
| import ReceiptAlternativeMethods from '@components/ReceiptAlternativeMethods'; | ||
| import Text from '@components/Text'; | ||
| import {useMemoizedLazyExpensifyIcons, useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useTheme from '@hooks/useTheme'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import StepScreenDragAndDropWrapper from '@pages/iou/request/step/StepScreenDragAndDropWrapper'; | ||
| import CONST from '@src/CONST'; | ||
| import type {FileObject} from '@src/types/utils/Attachment'; | ||
|
|
||
| type DesktopWebUploadViewProps = { | ||
| PDFValidationComponent: React.ReactNode; | ||
| shouldAcceptMultipleFiles: boolean; | ||
| isReplacingReceipt: boolean; | ||
| onLayout: () => void; | ||
| validateFiles: (files: FileObject[], items?: DataTransferItem[]) => void; | ||
| onBackButtonPress: () => void; | ||
| shouldShowWrapper: boolean; | ||
| }; | ||
|
|
||
| function DesktopWebUploadView({ | ||
| PDFValidationComponent, | ||
| shouldAcceptMultipleFiles, | ||
| isReplacingReceipt, | ||
| onLayout, | ||
| validateFiles, | ||
| onBackButtonPress, | ||
| shouldShowWrapper, | ||
| }: DesktopWebUploadViewProps) { | ||
| const theme = useTheme(); | ||
| const styles = useThemeStyles(); | ||
| const {translate} = useLocalize(); | ||
| const lazyIllustrations = useMemoizedLazyIllustrations(['ReceiptStack']); | ||
| const lazyIcons = useMemoizedLazyExpensifyIcons(['ReplaceReceipt', 'SmartScan']); | ||
| const panResponder = useRef( | ||
| PanResponder.create({ | ||
| onPanResponderTerminationRequest: () => false, | ||
| }), | ||
| ).current; | ||
|
|
||
| const [containerHeight, setContainerHeight] = useState(0); | ||
| const [desktopUploadViewHeight, setDesktopUploadViewHeight] = useState(0); | ||
| const [alternativeMethodsHeight, setAlternativeMethodsHeight] = useState(0); | ||
| const chooseFilesPaddingVertical = Number(styles.chooseFilesView(false).paddingVertical); | ||
| const shouldHideAlternativeMethods = alternativeMethodsHeight + desktopUploadViewHeight + chooseFilesPaddingVertical * 2 > containerHeight; | ||
|
|
||
| const handleDropReceipt = (e: DragEvent) => { | ||
| const files = Array.from(e?.dataTransfer?.files ?? []); | ||
| if (files.length === 0) { | ||
| return; | ||
| } | ||
| for (const file of files) { | ||
| // eslint-disable-next-line no-param-reassign | ||
| file.uri = URL.createObjectURL(file); | ||
| } | ||
|
|
||
| validateFiles(files, Array.from(e.dataTransfer?.items ?? [])); | ||
| }; | ||
|
|
||
| return ( | ||
| <StepScreenDragAndDropWrapper | ||
| headerTitle={translate('common.receipt')} | ||
| onBackButtonPress={onBackButtonPress} | ||
| shouldShowWrapper={shouldShowWrapper} | ||
| testID="IOURequestStepScan" | ||
| > | ||
| {(isDraggingOver) => ( | ||
| <View | ||
| onLayout={(event) => { | ||
| setContainerHeight(event.nativeEvent.layout.height); | ||
| onLayout(); | ||
| }} | ||
| style={[styles.flex1, styles.chooseFilesView(false)]} | ||
| > | ||
| <View style={[styles.flex1, styles.alignItemsCenter, styles.justifyContentCenter]}> | ||
| {!isDraggingOver && ( | ||
| <View | ||
| style={[styles.alignItemsCenter, styles.justifyContentCenter]} | ||
| onLayout={(e) => { | ||
| setDesktopUploadViewHeight(e.nativeEvent.layout.height); | ||
| }} | ||
| > | ||
| {PDFValidationComponent} | ||
| <Icon | ||
| src={lazyIllustrations.ReceiptStack} | ||
| width={CONST.RECEIPT.ICON_SIZE} | ||
| height={CONST.RECEIPT.ICON_SIZE} | ||
| /> | ||
| <View | ||
| style={[styles.uploadFileViewTextContainer, styles.userSelectNone]} | ||
| // eslint-disable-next-line react/jsx-props-no-spreading, react-hooks/refs | ||
| {...panResponder.panHandlers} | ||
| > | ||
| <Text style={[styles.textFileUpload, styles.mb2]}>{translate(shouldAcceptMultipleFiles ? 'receipt.uploadMultiple' : 'receipt.upload')}</Text> | ||
| <Text style={[styles.textLabelSupporting, styles.textAlignCenter, styles.lineHeightLarge]}> | ||
| {translate(shouldAcceptMultipleFiles ? 'receipt.desktopSubtitleMultiple' : 'receipt.desktopSubtitleSingle')} | ||
| </Text> | ||
| </View> | ||
|
|
||
| <AttachmentPicker allowMultiple={shouldAcceptMultipleFiles}> | ||
| {({openPicker}) => ( | ||
| <Button | ||
| success | ||
| text={translate(shouldAcceptMultipleFiles ? 'common.chooseFiles' : 'common.chooseFile')} | ||
| accessibilityLabel={translate(shouldAcceptMultipleFiles ? 'common.chooseFiles' : 'common.chooseFile')} | ||
| style={[styles.p5]} | ||
| onPress={() => { | ||
| openPicker({ | ||
| onPicked: (data) => validateFiles(data), | ||
| }); | ||
| }} | ||
| sentryLabel={CONST.SENTRY_LABEL.IOU_REQUEST_STEP.SCAN_SUBMIT_BUTTON} | ||
| /> | ||
| )} | ||
| </AttachmentPicker> | ||
| </View> | ||
| )} | ||
| </View> | ||
| <DragAndDropConsumer onDrop={handleDropReceipt}> | ||
| <DropZoneUI | ||
| icon={isReplacingReceipt ? lazyIcons.ReplaceReceipt : lazyIcons.SmartScan} | ||
| dropStyles={styles.receiptDropOverlay(true)} | ||
| dropTitle={isReplacingReceipt ? translate('dropzone.replaceReceipt') : translate(shouldAcceptMultipleFiles ? 'dropzone.scanReceipts' : 'quickAction.scanReceipt')} | ||
| dropTextStyles={styles.receiptDropText} | ||
| dashedBorderStyles={[styles.dropzoneArea, styles.easeInOpacityTransition, styles.activeDropzoneDashedBorder(theme.receiptDropBorderColorActive, true)]} | ||
| /> | ||
| </DragAndDropConsumer> | ||
| {!shouldHideAlternativeMethods && <ReceiptAlternativeMethods onLayout={(e) => setAlternativeMethodsHeight(e.nativeEvent.layout.height)} />} | ||
| </View> | ||
| )} | ||
| </StepScreenDragAndDropWrapper> | ||
| ); | ||
| } | ||
|
|
||
| export default DesktopWebUploadView; | ||
| export type {DesktopWebUploadViewProps}; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we see the code before refactor, we get the
isDraggingOverboth from theuseDragAndDropStateand the wrapper, so let's keep it like that to prevent unwanted regression.