Skip to content

Commit 9a194e5

Browse files
committed
fix: improve image performance
1 parent 003ebde commit 9a194e5

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

  • apps/mobile/src/components/ui/image

apps/mobile/src/components/ui/image/utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ export const getAllSources = (
3838
},
3939
) => {
4040
if (!isImageSourceWithUri(source)) {
41+
console.warn("Invalid image source", source)
4142
return [undefined, undefined] as const
4243
}
4344

4445
// Now TypeScript knows source has a uri property
4546
source.uri = source.uri.replace("http://", "https://")
4647

4748
const safeSource: ImageProps["source"] = {
49+
width: proxy?.width,
50+
height: proxy?.height,
4851
...source,
4952
headers: {
5053
...buildSafeHeaders({ url: source.uri }),
@@ -58,13 +61,15 @@ export const getAllSources = (
5861
}
5962

6063
return {
64+
width: proxy?.width,
65+
height: proxy?.height,
6166
...safeSource,
6267
uri: getImageProxyUrl({
6368
url: source.uri,
6469
width: proxy?.width ? proxy?.width * 3 : undefined,
6570
height: proxy?.height ? proxy?.height * 3 : undefined,
6671
}),
67-
}
72+
} satisfies ImageProps["source"]
6873
})()
6974

7075
return [safeSource, proxiesSafeSource] as const
@@ -74,9 +79,8 @@ const getImageData = async (imageUrl: string) => {
7479
let size = await Image.getSize(imageUrl)
7580

7681
// Workaround for Android where the size returned by Image.getSize is not accurate for remote images
77-
// https://github.com/facebook/react-native/issues/33498
82+
// Learn more https://github.com/facebook/react-native/issues/33498
7883
if (isAndroid) {
79-
// If the image is not a remote URL, we can use the local file path directly
8084
size = {
8185
width: size.width * 10,
8286
height: size.height * 10,

0 commit comments

Comments
 (0)