-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Decompose scan pr2 camera multiscan #87883
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,126 @@ | ||||
| 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 {useDragAndDropState} from '@components/DragAndDrop/Provider'; | ||||
| 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 CONST from '@src/CONST'; | ||||
| import type {FileObject} from '@src/types/utils/Attachment'; | ||||
| import type {CameraProps} from './types'; | ||||
|
|
||||
| /** | ||||
| * FileUpload — desktop web capture variant. | ||||
| * Renders a drag-and-drop zone + file picker button + receipt alternative methods. | ||||
| */ | ||||
| function FileUpload({onDrop, shouldAcceptMultipleFiles = false, onLayout}: CameraProps) { | ||||
| const theme = useTheme(); | ||||
| const styles = useThemeStyles(); | ||||
| const {translate} = useLocalize(); | ||||
| const lazyIllustrations = useMemoizedLazyIllustrations(['ReceiptStack']); | ||||
| const lazyIcons = useMemoizedLazyExpensifyIcons(['SmartScan']); | ||||
|
|
||||
| const panResponderRef = useRef( | ||||
| PanResponder.create({ | ||||
| onPanResponderTerminationRequest: () => false, | ||||
| }), | ||||
| ); | ||||
|
|
||||
| const {isDraggingOver} = useDragAndDropState(); | ||||
|
|
||||
| // Height-based hiding for ReceiptAlternativeMethods | ||||
| const [containerHeight, setContainerHeight] = useState(0); | ||||
| const [uploadViewHeight, setUploadViewHeight] = useState(0); | ||||
| const [altMethodsHeight, setAltMethodsHeight] = useState(0); | ||||
| const chooseFilesPaddingVertical = Number(styles.chooseFilesView(false).paddingVertical); | ||||
| const shouldHideAlternativeMethods = altMethodsHeight + uploadViewHeight + chooseFilesPaddingVertical * 2 > containerHeight; | ||||
|
|
||||
| const handleDrop = (e: DragEvent) => { | ||||
| const rawFiles = Array.from(e?.dataTransfer?.files ?? []); | ||||
| if (rawFiles.length === 0) { | ||||
| return; | ||||
| } | ||||
| const files: FileObject[] = rawFiles.map((file) => { | ||||
| // eslint-disable-next-line no-param-reassign | ||||
| file.uri = URL.createObjectURL(file); | ||||
| return file; | ||||
| }); | ||||
|
|
||||
| if (onDrop) { | ||||
| onDrop(files, Array.from(e.dataTransfer?.items ?? [])); | ||||
| } | ||||
| }; | ||||
|
|
||||
| return ( | ||||
| <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) => setUploadViewHeight(e.nativeEvent.layout.height)} | ||||
| > | ||||
| <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 | ||||
| {...panResponderRef.current.panHandlers} | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CONSISTENCY-5 (docs)The Add a comment explaining the reason, for example: {/* PanResponder handlers must be spread onto the View for gesture recognition */}
{/* eslint-disable-next-line react/jsx-props-no-spreading, react-hooks/refs */}
{...panResponderRef.current.panHandlers}Reviewed at: 81d47b7 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency. |
||||
| > | ||||
| <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) => onDrop?.(data, []), | ||||
| }); | ||||
| }} | ||||
| sentryLabel={CONST.SENTRY_LABEL.IOU_REQUEST_STEP.SCAN_SUBMIT_BUTTON} | ||||
| /> | ||||
| )} | ||||
| </AttachmentPicker> | ||||
| </View> | ||||
| )} | ||||
| </View> | ||||
| <DragAndDropConsumer onDrop={handleDrop}> | ||||
| <DropZoneUI | ||||
| icon={lazyIcons.SmartScan} | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the plan for the "replace" case here? App/src/pages/iou/request/step/IOURequestStepScan/components/DesktopWebUploadView.tsx Line 130 in 9a23626
Maybe we can pass the |
||||
| dropStyles={styles.receiptDropOverlay(true)} | ||||
| dropTitle={translate(shouldAcceptMultipleFiles ? 'dropzone.scanReceipts' : 'quickAction.scanReceipt')} | ||||
| dropTextStyles={styles.receiptDropText} | ||||
| dashedBorderStyles={[styles.dropzoneArea, styles.easeInOpacityTransition, styles.activeDropzoneDashedBorder(theme.receiptDropBorderColorActive, true)]} | ||||
| /> | ||||
| </DragAndDropConsumer> | ||||
| {!shouldHideAlternativeMethods && <ReceiptAlternativeMethods onLayout={(e) => setAltMethodsHeight(e.nativeEvent.layout.height)} />} | ||||
| </View> | ||||
| ); | ||||
| } | ||||
|
|
||||
| FileUpload.displayName = 'FileUpload'; | ||||
|
|
||||
| export default FileUpload; | ||||
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.
We previously also used
isDraggingOverWrapperfrom theStepScreenDragAndDropWrapper.App/src/pages/iou/request/step/IOURequestStepScan/components/DesktopWebUploadView.tsx
Line 85 in 9a23626
So, in prod, we get the isDraggingOver state from 2 providers.
1 from IOURequestStartPage, and 1 from the StepScreenDragAndDropWrapper. In this PR, we only get it from IOURequestStartPage.