From 4e5ce39c80a6d8012491c206f1788d4858d921c1 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Thu, 27 Mar 2025 17:42:53 +0100 Subject: [PATCH 1/5] fix attachment preview becomes blank --- src/components/AttachmentPreview.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/AttachmentPreview.tsx b/src/components/AttachmentPreview.tsx index c845833d8df7..a13a7b452191 100644 --- a/src/components/AttachmentPreview.tsx +++ b/src/components/AttachmentPreview.tsx @@ -8,7 +8,7 @@ import {checkIsFileImage} from './Attachments/AttachmentView'; import DefaultAttachmentView from './Attachments/AttachmentView/DefaultAttachmentView'; import Icon from './Icon'; import * as Expensicons from './Icon/Expensicons'; -import ImageView from './ImageView'; +import Image from './Image'; import PDFThumbnail from './PDFThumbnail'; import {PressableWithFeedback} from './Pressable'; @@ -79,9 +79,9 @@ function AttachmentPreview({source, aspectRatio = 1, onPress, onLoadError}: Atta accessibilityLabel="Image Thumbnail" > - From 87bbb83d10b42a4046e91e32c7eeafa2688c5f9b Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Thu, 27 Mar 2025 17:43:50 +0100 Subject: [PATCH 2/5] alert modal reappearing and no file to large error --- src/pages/Share/ShareDetailsPage.tsx | 2 +- src/pages/Share/ShareRootPage.tsx | 47 ++++++++++++++++++---------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/pages/Share/ShareDetailsPage.tsx b/src/pages/Share/ShareDetailsPage.tsx index 620b98bab927..ef71c4b71615 100644 --- a/src/pages/Share/ShareDetailsPage.tsx +++ b/src/pages/Share/ShareDetailsPage.tsx @@ -68,7 +68,7 @@ function ShareDetailsPage({ if (isTextShared) { addComment(report.reportID, message); const routeToNavigate = ROUTES.REPORT_WITH_ID.getRoute(reportOrAccountID); - Navigation.navigate(routeToNavigate); + Navigation.navigate(routeToNavigate, {forceReplace: true}); return; } diff --git a/src/pages/Share/ShareRootPage.tsx b/src/pages/Share/ShareRootPage.tsx index de8da74f2fa3..454eb527cb11 100644 --- a/src/pages/Share/ShareRootPage.tsx +++ b/src/pages/Share/ShareRootPage.tsx @@ -1,5 +1,6 @@ import React, {useCallback, useEffect, useRef, useState} from 'react'; import {Alert, AppState, View} from 'react-native'; +import RNFS from 'react-native-fs'; import type {FileObject} from '@components/AttachmentModal'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; @@ -39,33 +40,47 @@ function ShareRootPage() { const [isFileScannable, setIsFileScannable] = useState(false); const receiptFileFormats = Object.values(CONST.RECEIPT_ALLOWED_FILE_TYPES) as string[]; const shareFileMimetypes = Object.values(CONST.SHARE_FILE_MIMETYPE) as string[]; + const [errorTitle, setErrorTitle] = useState(undefined); + const [errorMessage, setErrorMessage] = useState(undefined); + + useEffect(() => { + if (!errorTitle || !errorMessage) { + return; + } + + showErrorAlert(errorTitle, errorMessage); + }, [errorTitle, errorMessage]); const handleProcessFiles = useCallback(() => { ShareActionHandler.processFiles((processedFiles) => { const tempFile = Array.isArray(processedFiles) ? processedFiles.at(0) : (JSON.parse(processedFiles) as ShareTempFile); if (!tempFile?.mimeType || !shareFileMimetypes.includes(tempFile?.mimeType)) { - showErrorAlert(translate('attachmentPicker.wrongFileType'), translate('attachmentPicker.notAllowedExtension')); + setErrorTitle(translate('attachmentPicker.wrongFileType')); + setErrorMessage(translate('attachmentPicker.notAllowedExtension')); return; } + if (tempFile?.mimeType && tempFile?.mimeType !== 'txt') { + RNFS.stat(tempFile?.content).then((fileStat) => { + if (fileStat.size > CONST.API_ATTACHMENT_VALIDATIONS.MAX_SIZE) { + setErrorTitle(translate('attachmentPicker.attachmentTooLarge')); + setErrorMessage(translate('attachmentPicker.sizeExceeded')); + } + + if (fileStat.size < CONST.API_ATTACHMENT_VALIDATIONS.MIN_SIZE) { + setErrorTitle(translate('attachmentPicker.attachmentTooSmall')); + setErrorMessage(translate('attachmentPicker.sizeNotMet')); + } + }); + } + const fileRegexp = /image\/.*/; if (fileRegexp.test(tempFile?.mimeType)) { const fileObject: FileObject = {name: tempFile.id, uri: tempFile?.content, type: tempFile?.mimeType}; - validateImageForCorruption(fileObject) - .then(() => { - if (fileObject.size && fileObject.size > CONST.API_ATTACHMENT_VALIDATIONS.MAX_SIZE) { - showErrorAlert(translate('attachmentPicker.attachmentTooLarge'), translate('attachmentPicker.sizeExceeded')); - } - - if (fileObject.size && fileObject.size < CONST.API_ATTACHMENT_VALIDATIONS.MIN_SIZE) { - showErrorAlert(translate('attachmentPicker.attachmentTooSmall'), translate('attachmentPicker.sizeNotMet')); - } - - return true; - }) - .catch(() => { - showErrorAlert(translate('attachmentPicker.attachmentError'), translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); - }); + validateImageForCorruption(fileObject).catch(() => { + setErrorTitle(translate('attachmentPicker.attachmentError')); + setErrorMessage(translate('attachmentPicker.errorWhileSelectingCorruptedAttachment')); + }); } const {fileExtension} = splitExtensionFromFileName(tempFile?.content); From f5081df9a268afefa6cc8d18aba98cb6064f26a3 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Fri, 28 Mar 2025 16:02:48 +0100 Subject: [PATCH 3/5] fix build error --- src/pages/Share/ShareRootPage.tsx | 8 ++++---- src/pages/Share/getFileSize/index.native.ts | 10 ++++++++++ src/pages/Share/getFileSize/index.ts | 7 +++++++ src/pages/Share/getFileSize/types.ts | 3 +++ 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 src/pages/Share/getFileSize/index.native.ts create mode 100644 src/pages/Share/getFileSize/index.ts create mode 100644 src/pages/Share/getFileSize/types.ts diff --git a/src/pages/Share/ShareRootPage.tsx b/src/pages/Share/ShareRootPage.tsx index 454eb527cb11..b9496dc00c04 100644 --- a/src/pages/Share/ShareRootPage.tsx +++ b/src/pages/Share/ShareRootPage.tsx @@ -1,6 +1,5 @@ import React, {useCallback, useEffect, useRef, useState} from 'react'; import {Alert, AppState, View} from 'react-native'; -import RNFS from 'react-native-fs'; import type {FileObject} from '@components/AttachmentModal'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; @@ -17,6 +16,7 @@ import ShareActionHandler from '@libs/ShareActionHandlerModule'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import type {ShareTempFile} from '@src/types/onyx'; +import getFileSize from './getFileSize'; import ShareTab from './ShareTab'; import SubmitTab from './SubmitTab'; @@ -61,13 +61,13 @@ function ShareRootPage() { } if (tempFile?.mimeType && tempFile?.mimeType !== 'txt') { - RNFS.stat(tempFile?.content).then((fileStat) => { - if (fileStat.size > CONST.API_ATTACHMENT_VALIDATIONS.MAX_SIZE) { + getFileSize(tempFile?.content).then((size) => { + if (size > CONST.API_ATTACHMENT_VALIDATIONS.MAX_SIZE) { setErrorTitle(translate('attachmentPicker.attachmentTooLarge')); setErrorMessage(translate('attachmentPicker.sizeExceeded')); } - if (fileStat.size < CONST.API_ATTACHMENT_VALIDATIONS.MIN_SIZE) { + if (size < CONST.API_ATTACHMENT_VALIDATIONS.MIN_SIZE) { setErrorTitle(translate('attachmentPicker.attachmentTooSmall')); setErrorMessage(translate('attachmentPicker.sizeNotMet')); } diff --git a/src/pages/Share/getFileSize/index.native.ts b/src/pages/Share/getFileSize/index.native.ts new file mode 100644 index 000000000000..c008f37b2fab --- /dev/null +++ b/src/pages/Share/getFileSize/index.native.ts @@ -0,0 +1,10 @@ +import RNFS from 'react-native-fs'; +import type GetFileSizeType from './types'; + +const getFileSize: GetFileSizeType = (uri: string) => { + return RNFS.stat(uri).then((fileStat) => { + return fileStat.size; + }); +}; + +export default getFileSize; diff --git a/src/pages/Share/getFileSize/index.ts b/src/pages/Share/getFileSize/index.ts new file mode 100644 index 000000000000..41f9be06b5d1 --- /dev/null +++ b/src/pages/Share/getFileSize/index.ts @@ -0,0 +1,7 @@ +import type GetFileSizeType from './types'; + +const getFileSize: GetFileSizeType = () => { + return Promise.resolve(0); +}; + +export default getFileSize; diff --git a/src/pages/Share/getFileSize/types.ts b/src/pages/Share/getFileSize/types.ts new file mode 100644 index 000000000000..e8739f5294f4 --- /dev/null +++ b/src/pages/Share/getFileSize/types.ts @@ -0,0 +1,3 @@ +type GetFileSizeType = (uri: string) => Promise; + +export default GetFileSizeType; From e3a41e9ce216b3801a1e599058291b8ca3b8d10f Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Wed, 9 Apr 2025 12:07:54 +0200 Subject: [PATCH 4/5] Fix overflow and message styling issues --- src/components/AttachmentPreview.tsx | 19 +++-- src/components/PDFThumbnail/index.native.tsx | 4 +- src/components/PDFThumbnail/types.ts | 3 + src/pages/Share/ShareDetailsPage.tsx | 73 +++++++++++--------- 4 files changed, 59 insertions(+), 40 deletions(-) diff --git a/src/components/AttachmentPreview.tsx b/src/components/AttachmentPreview.tsx index a13a7b452191..0f169ddd8008 100644 --- a/src/components/AttachmentPreview.tsx +++ b/src/components/AttachmentPreview.tsx @@ -90,11 +90,20 @@ function AttachmentPreview({source, aspectRatio = 1, onPress, onLoadError}: Atta if (typeof source === 'string' && Str.isPDF(source) && !isEncryptedPDF) { return ( - setIsEncryptedPDF(true)} - /> + + setIsEncryptedPDF(true)} + /> + ); } diff --git a/src/components/PDFThumbnail/index.native.tsx b/src/components/PDFThumbnail/index.native.tsx index 66a42f6f0830..f7cb422ddb18 100644 --- a/src/components/PDFThumbnail/index.native.tsx +++ b/src/components/PDFThumbnail/index.native.tsx @@ -7,7 +7,7 @@ import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; import PDFThumbnailError from './PDFThumbnailError'; import type PDFThumbnailProps from './types'; -function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword, onLoadError, onLoadSuccess}: PDFThumbnailProps) { +function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, fitPolicy = 0, onPassword, onLoadError, onLoadSuccess}: PDFThumbnailProps) { const styles = useThemeStyles(); const sizeStyles = [styles.w100, styles.h100]; const [failedToLoad, setFailedToLoad] = useState(false); @@ -17,7 +17,7 @@ function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, ena {enabled && !failedToLoad && ( } source={{uri: isAuthTokenRequired ? addEncryptedAuthTokenToURL(previewSourceURL) : previewSourceURL}} diff --git a/src/components/PDFThumbnail/types.ts b/src/components/PDFThumbnail/types.ts index 3d79e7c026d2..ca95bdc55bc7 100644 --- a/src/components/PDFThumbnail/types.ts +++ b/src/components/PDFThumbnail/types.ts @@ -13,6 +13,9 @@ type PDFThumbnailProps = { /** Whether the PDF thumbnail can be loaded */ enabled?: boolean; + /** Fit policy for the PDF thumbnail */ + fitPolicy?: number; + /** Callback to call if PDF is password protected */ onPassword?: () => void; diff --git a/src/pages/Share/ShareDetailsPage.tsx b/src/pages/Share/ShareDetailsPage.tsx index ef71c4b71615..8211b97e8815 100644 --- a/src/pages/Share/ShareDetailsPage.tsx +++ b/src/pages/Share/ShareDetailsPage.tsx @@ -11,7 +11,6 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton'; import {FallbackAvatar} from '@components/Icon/Expensicons'; import {PressableWithoutFeedback} from '@components/Pressable'; import ScreenWrapper from '@components/ScreenWrapper'; -import ScrollView from '@components/ScrollView'; import Text from '@components/Text'; import TextInput from '@components/TextInput'; import useLocalize from '@hooks/useLocalize'; @@ -24,6 +23,7 @@ import type {ShareNavigatorParamList} from '@libs/Navigation/types'; import {getReportDisplayOption} from '@libs/OptionsListUtils'; import {getReportOrDraftReport, isDraftReport} from '@libs/ReportUtils'; import NotFoundPage from '@pages/ErrorPage/NotFoundPage'; +import variables from '@styles/variables'; import UserListItem from '@src/components/SelectionList/UserListItem'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -100,20 +100,20 @@ function ShareDetailsPage({ }; return ( - { - KeyboardUtils.dismiss(); - }} - accessible={false} + - - + + { + KeyboardUtils.dismiss(); + }} + accessible={false} + > )} - - - - - - - + + + + + + { + KeyboardUtils.dismiss(); + }} + accessible={false} + > {shouldShowAttachment && ( <> @@ -176,19 +183,19 @@ function ShareDetailsPage({ )} - + - +