Skip to content

Commit

Permalink
display loading while image is resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
nkdengineer committed Aug 7, 2024
1 parent dd5a9e1 commit e779b07
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Shutter from '@assets/images/shutter.svg';
import type {FileObject} from '@components/AttachmentModal';
import AttachmentPicker from '@components/AttachmentPicker';
import Button from '@components/Button';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import ImageSVG from '@components/ImageSVG';
Expand Down Expand Up @@ -67,6 +68,7 @@ function IOURequestStepScan({
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? -1}`);
const [cameraPermissionStatus, setCameraPermissionStatus] = useState<string | null>(null);
const [didCapturePhoto, setDidCapturePhoto] = useState(false);
const [isLoadingReceipt, setIsLoadingReceipt] = useState(false);

const [pdfFile, setPdfFile] = useState<null | FileObject>(null);

Expand Down Expand Up @@ -398,7 +400,13 @@ function IOURequestStepScan({
return;
}

// With the image size > 24MB, we use manipulateAsync to resize the image.
// It takes a long time so we should display a loading indicator while the resize image progresses.
if (Str.isImage(originalFile.name ?? '') && (originalFile?.size ?? 0) > CONST.API_ATTACHMENT_VALIDATIONS.MAX_SIZE) {
setIsLoadingReceipt(true);
}
FileUtils.resizeImageIfNeeded(originalFile).then((file) => {
setIsLoadingReceipt(false);
// Store the receipt on the transaction object in Onyx
// On Android devices, fetching blob for a file with name containing spaces fails to retrieve the type of file.
// So, let us also save the file type in receipt for later use during blob fetch
Expand Down Expand Up @@ -470,6 +478,7 @@ function IOURequestStepScan({
shouldShowWrapper={!!backTo}
testID={IOURequestStepScan.displayName}
>
{isLoadingReceipt && <FullScreenLoadingIndicator />}
{pdfFile && (
<PDFThumbnail
style={styles.invisiblePDF}
Expand Down
10 changes: 10 additions & 0 deletions src/pages/iou/request/step/IOURequestStepScan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Button from '@components/Button';
import ConfirmModal from '@components/ConfirmModal';
import CopyTextToClipboard from '@components/CopyTextToClipboard';
import {DragAndDropContext} from '@components/DragAndDrop/Provider';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import PDFThumbnail from '@components/PDFThumbnail';
Expand Down Expand Up @@ -78,6 +79,7 @@ function IOURequestStepScan({

const getScreenshotTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? -1}`);
const [isLoadingReceipt, setIsLoadingReceipt] = useState(false);

const [videoConstraints, setVideoConstraints] = useState<MediaTrackConstraints>();
const tabIndex = 1;
Expand Down Expand Up @@ -431,7 +433,13 @@ function IOURequestStepScan({
return;
}

// With the image size > 24MB, we use manipulateAsync to resize the image.
// It takes a long time so we should display a loading indicator while the resize image progresses.
if (Str.isImage(originalFile.name ?? '') && (originalFile?.size ?? 0) > CONST.API_ATTACHMENT_VALIDATIONS.MAX_SIZE) {
setIsLoadingReceipt(true);
}
FileUtils.resizeImageIfNeeded(originalFile).then((file) => {
setIsLoadingReceipt(false);
// Store the receipt on the transaction object in Onyx
const source = URL.createObjectURL(file as Blob);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand Down Expand Up @@ -541,6 +549,7 @@ function IOURequestStepScan({

const mobileCameraView = () => (
<>
{isLoadingReceipt && <FullScreenLoadingIndicator />}
<View style={[styles.cameraView]}>
{PDFThumbnailView}
{((cameraPermissionState === 'prompt' && !isQueriedPermissionState) || (cameraPermissionState === 'granted' && isEmptyObject(videoConstraints))) && (
Expand Down Expand Up @@ -641,6 +650,7 @@ function IOURequestStepScan({

const desktopUploadView = () => (
<>
{isLoadingReceipt && <FullScreenLoadingIndicator />}
{PDFThumbnailView}
<View onLayout={({nativeEvent}) => setReceiptImageTopPosition(PixelRatio.roundToNearestPixel((nativeEvent.layout as DOMRect).top))}>
<ReceiptUpload
Expand Down

0 comments on commit e779b07

Please sign in to comment.