Skip to content

Commit a6936e0

Browse files
committed
fix: refactor photo resolution to native level
1 parent baa5360 commit a6936e0

File tree

3 files changed

+23
-35
lines changed

3 files changed

+23
-35
lines changed

package/native-package/src/optionalDependencies/getLocalAssetUri.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ try {
1414
export const getLocalAssetUri = CameraRollDependency
1515
? async (remoteUri: string) => {
1616
try {
17-
let localUri = remoteUri;
1817
if (Platform.OS === 'ios') {
1918
const imageData = await CameraRollDependency.CameraRoll.iosGetImageDataById(remoteUri);
20-
localUri = imageData?.node?.image?.filepath;
19+
return imageData?.node?.image?.filepath;
2120
}
22-
return localUri;
21+
return remoteUri;
2322
} catch {
2423
throw new Error('getLocalAssetUri Error');
2524
}

package/native-package/src/optionalDependencies/getPhotos.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ try {
1313

1414
import type { Asset } from 'stream-chat-react-native-core';
1515

16+
import { getLocalAssetUri } from './getLocalAssetUri';
17+
1618
type ReturnType = {
1719
assets: Array<Omit<Asset, 'source'> & { source: 'picker' }>;
1820
endCursor: string | undefined;
@@ -82,15 +84,23 @@ export const getPhotos = CameraRollDependency
8284
first,
8385
include: ['fileSize', 'filename', 'imageSize', 'playableDuration'],
8486
});
85-
const assets = results.edges.map((edge) => ({
86-
...edge.node.image,
87-
duration: edge.node.image.playableDuration * 1000,
88-
// since we include filename, fileSize in the query, we can safely assume it will be defined
89-
name: edge.node.image.filename as string,
90-
size: edge.node.image.fileSize as number,
91-
source: 'picker' as const,
92-
type: edge.node.type,
93-
}));
87+
const assets = await Promise.all(
88+
results.edges.map(async (edge) => {
89+
const originalUri = edge.node?.image?.uri;
90+
const uri = getLocalAssetUri ? await getLocalAssetUri(originalUri) : originalUri;
91+
return {
92+
...edge.node.image,
93+
duration: edge.node.image.playableDuration * 1000,
94+
// since we include filename, fileSize in the query, we can safely assume it will be defined
95+
name: edge.node.image.filename as string,
96+
originalUri,
97+
size: edge.node.image.fileSize as number,
98+
source: 'picker' as const,
99+
type: edge.node.type,
100+
uri,
101+
};
102+
}),
103+
);
94104
const hasNextPage = results.page_info.has_next_page;
95105
const endCursor = results.page_info.end_cursor;
96106
return { assets, endCursor, hasNextPage, iOSLimited: !!results.limited };

package/src/components/AttachmentPicker/components/AttachmentPickerItem.tsx

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -158,33 +158,12 @@ const AttachmentImage = (props: AttachmentImageProps) => {
158158

159159
const { uri } = asset;
160160

161-
/* Patches image files with uri */
162-
const patchImageFile = async (images: Asset[]) => {
163-
// For the case of Expo CLI where you need to fetch the file uri from file id. Here it is only done for iOS since for android the file.uri is fine.
164-
const identifier = asset.id || asset.uri;
165-
const localAssetURI =
166-
Platform.OS === 'ios' &&
167-
identifier &&
168-
getLocalAssetUri &&
169-
(await getLocalAssetUri(identifier));
170-
const uri = localAssetURI || asset.uri || '';
171-
return [
172-
...images,
173-
{
174-
...asset,
175-
originalUri: asset.uri,
176-
uri,
177-
},
178-
];
179-
};
180-
181-
const updateSelectedImages = async () => {
161+
const updateSelectedImages = () => {
182162
if (numberOfUploads >= maxNumberOfFiles) {
183163
Alert.alert(t('Maximum number of files reached'));
184164
return;
185165
}
186-
const images = await patchImageFile(selectedImages);
187-
setSelectedImages(images);
166+
setSelectedImages([...selectedImages, asset]);
188167
};
189168

190169
const onPressImage = () => {

0 commit comments

Comments
 (0)