From 3bba36359ce316cf295c622d315b48a3a1d52b72 Mon Sep 17 00:00:00 2001 From: Linh Date: Fri, 22 Aug 2025 17:24:32 +0700 Subject: [PATCH 1/2] fix: can not share file if the file has specical character --- .../java/com/expensify/chat/ShareActionHandlerModule.kt | 3 ++- ios/RCTShareActionHandlerModule.m | 2 +- src/components/AttachmentPreview.tsx | 8 ++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/android/app/src/main/java/com/expensify/chat/ShareActionHandlerModule.kt b/android/app/src/main/java/com/expensify/chat/ShareActionHandlerModule.kt index dcb94d19a22d..14258ea744f9 100644 --- a/android/app/src/main/java/com/expensify/chat/ShareActionHandlerModule.kt +++ b/android/app/src/main/java/com/expensify/chat/ShareActionHandlerModule.kt @@ -36,7 +36,6 @@ class ShareActionHandlerModule(reactContext: ReactApplicationContext) : val shareObject = JSONObject(shareObjectString) val content = shareObject.optString("content") val mimeType = shareObject.optString("mimeType") - val fileUriPath = "file://$content" val timestamp = System.currentTimeMillis() val file = File(content) @@ -53,6 +52,8 @@ class ShareActionHandlerModule(reactContext: ReactApplicationContext) : val identifier = file.name var aspectRatio = 0.0f + val fileUri = android.net.Uri.fromFile(file) + val fileUriPath = fileUri.toString() if (mimeType.startsWith("image/")) { val options = BitmapFactory.Options().apply { inJustDecodeBounds = true } diff --git a/ios/RCTShareActionHandlerModule.m b/ios/RCTShareActionHandlerModule.m index e058c304e3f1..9999fe45368b 100644 --- a/ios/RCTShareActionHandlerModule.m +++ b/ios/RCTShareActionHandlerModule.m @@ -86,7 +86,7 @@ - (NSDictionary *)processSingleFile:(NSString *)filePath { } else if ([mimeType hasPrefix:@"image/"]) { aspectRatio = [self imageAspectRatio:fileURL]; } - fileContent = [@"file://" stringByAppendingString:filePath]; + fileContent = [fileURL absoluteString]; } NSString *identifier = [self uniqueIdentifierForFilePath:filePath]; diff --git a/src/components/AttachmentPreview.tsx b/src/components/AttachmentPreview.tsx index 3fee12304160..8ccb609ea5a8 100644 --- a/src/components/AttachmentPreview.tsx +++ b/src/components/AttachmentPreview.tsx @@ -1,8 +1,9 @@ import {Str} from 'expensify-common'; import {ResizeMode, Video} from 'expo-av'; -import React, {useState} from 'react'; +import React, {useMemo, useState} from 'react'; import {View} from 'react-native'; import useThemeStyles from '@hooks/useThemeStyles'; +import {cleanFileName, getFileName} from '@libs/fileDownload/FileUtils'; import variables from '@styles/variables'; import {checkIsFileImage} from './Attachments/AttachmentView'; import DefaultAttachmentView from './Attachments/AttachmentView/DefaultAttachmentView'; @@ -29,9 +30,12 @@ type AttachmentPreviewProps = { function AttachmentPreview({source, aspectRatio = 1, onPress, onLoadError}: AttachmentPreviewProps) { const styles = useThemeStyles(); - const fileName = source.split('/').pop() ?? undefined; const fillStyle = aspectRatio < 1 ? styles.h100 : styles.w100; const [isEncryptedPDF, setIsEncryptedPDF] = useState(false); + const fileName = useMemo(() => { + const rawFileName = getFileName(source); + return cleanFileName(rawFileName ?? ''); + }, [source]); if (typeof source === 'string' && Str.isVideo(source)) { return ( From 16a090930b5da4dbc72817f3921c484e78c45d4a Mon Sep 17 00:00:00 2001 From: Linh Date: Fri, 22 Aug 2025 17:34:07 +0700 Subject: [PATCH 2/2] chore: remove default value --- src/components/AttachmentPreview.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AttachmentPreview.tsx b/src/components/AttachmentPreview.tsx index 8ccb609ea5a8..560be3304cff 100644 --- a/src/components/AttachmentPreview.tsx +++ b/src/components/AttachmentPreview.tsx @@ -34,7 +34,7 @@ function AttachmentPreview({source, aspectRatio = 1, onPress, onLoadError}: Atta const [isEncryptedPDF, setIsEncryptedPDF] = useState(false); const fileName = useMemo(() => { const rawFileName = getFileName(source); - return cleanFileName(rawFileName ?? ''); + return cleanFileName(rawFileName); }, [source]); if (typeof source === 'string' && Str.isVideo(source)) {