Skip to content

Commit dfb1bfa

Browse files
committed
fix: use getResizedImageUrl for image
1 parent 8c655b0 commit dfb1bfa

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

package/src/components/ImageGallery/ImageGallery.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ export const ImageGallery = (props: Props) => {
383383
previous={currentIndex > i}
384384
scale={scale}
385385
screenHeight={fullWindowHeight}
386+
screenWidth={fullWindowWidth}
386387
selected={currentIndex === i}
387388
shouldRender={Math.abs(currentIndex - i) < 4}
388389
style={[

package/src/components/ImageGallery/components/AnimatedGalleryImage.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import React from 'react';
1+
import React, { useMemo } from 'react';
22
import { View } from 'react-native';
33
import type { ImageStyle, StyleProp } from 'react-native';
44
import Animated, { SharedValue } from 'react-native-reanimated';
55

6+
import { useChatConfigContext } from '../../../contexts/chatConfigContext/ChatConfigContext';
7+
import { getResizedImageUrl } from '../../../utils/getResizedImageUrl';
68
import { useAnimatedGalleryStyle } from '../hooks/useAnimatedGalleryStyle';
79

810
const oneEighth = 1 / 8;
@@ -15,6 +17,7 @@ type Props = {
1517
previous: boolean;
1618
scale: SharedValue<number>;
1719
screenHeight: number;
20+
screenWidth: number;
1821
selected: boolean;
1922
shouldRender: boolean;
2023
translateX: SharedValue<number>;
@@ -32,12 +35,23 @@ export const AnimatedGalleryImage = React.memo(
3235
previous,
3336
scale,
3437
screenHeight,
38+
screenWidth,
3539
selected,
3640
shouldRender,
3741
style,
3842
translateX,
3943
translateY,
4044
} = props;
45+
const { resizableCDNHosts } = useChatConfigContext();
46+
47+
const uri = useMemo(() => {
48+
return getResizedImageUrl({
49+
height: screenHeight,
50+
resizableCDNHosts,
51+
url: photo.uri,
52+
width: screenWidth,
53+
});
54+
}, [photo.uri, resizableCDNHosts, screenHeight, screenWidth]);
4155

4256
const animatedStyles = useAnimatedGalleryStyle({
4357
index,
@@ -63,7 +77,7 @@ export const AnimatedGalleryImage = React.memo(
6377
<Animated.Image
6478
accessibilityLabel={accessibilityLabel}
6579
resizeMode={'contain'}
66-
source={{ uri: photo.uri }}
80+
source={{ uri }}
6781
style={[...animatedStyles, style]}
6882
/>
6983
);
@@ -75,7 +89,8 @@ export const AnimatedGalleryImage = React.memo(
7589
prevProps.photo.uri === nextProps.photo.uri &&
7690
prevProps.previous === nextProps.previous &&
7791
prevProps.index === nextProps.index &&
78-
prevProps.screenHeight === nextProps.screenHeight
92+
prevProps.screenHeight === nextProps.screenHeight &&
93+
prevProps.screenWidth === nextProps.screenWidth
7994
) {
8095
return true;
8196
}

0 commit comments

Comments
 (0)