Fix a huge memory issue due to expo/expo#24894

This commit is contained in:
Dan Abramov
2024-11-08 18:04:16 +00:00
parent 24b39ccc04
commit e7f6bca63d
2 changed files with 38 additions and 40 deletions
@@ -31,8 +31,6 @@ import {
TransformMatrix, TransformMatrix,
} from '../../transforms' } from '../../transforms'
const AnimatedImage = Animated.createAnimatedComponent(Image)
const MIN_SCREEN_ZOOM = 2 const MIN_SCREEN_ZOOM = 2
const MAX_ORIGINAL_IMAGE_ZOOM = 2 const MAX_ORIGINAL_IMAGE_ZOOM = 2
@@ -344,14 +342,10 @@ const ImageItem = ({
} }
}) })
const type = imageSrc.type
const borderRadius =
type === 'circle-avi' ? 1e5 : type === 'rect-avi' ? 20 : 0
const imageStyle = useAnimatedStyle(() => { const imageStyle = useAnimatedStyle(() => {
const {cropContentTransform} = transforms.value const {cropContentTransform} = transforms.value
return { return {
flex: 1, flex: 1,
borderRadius,
transform: cropContentTransform, transform: cropContentTransform,
} }
}) })
@@ -371,13 +365,17 @@ const ImageItem = ({
}, },
) )
const type = imageSrc.type
const borderRadius =
type === 'circle-avi' ? 1e5 : type === 'rect-avi' ? 20 : 0
return ( return (
<GestureDetector gesture={composedGesture}> <GestureDetector gesture={composedGesture}>
<Animated.View <Animated.View
ref={containerRef} ref={containerRef}
style={[styles.container]} style={[styles.container]}
renderToHardwareTextureAndroid> renderToHardwareTextureAndroid>
<Animated.View style={containerStyle} renderToHardwareTextureAndroid> <Animated.View style={containerStyle}>
{showLoader && ( {showLoader && (
<ActivityIndicator <ActivityIndicator
size="small" size="small"
@@ -385,16 +383,16 @@ const ImageItem = ({
style={styles.loading} style={styles.loading}
/> />
)} )}
<Animated.View style={imageCropStyle} renderToHardwareTextureAndroid> <Animated.View style={imageCropStyle}>
<AnimatedImage <Animated.View style={imageStyle}>
renderToHardwareTextureAndroid <Image
contentFit="cover" contentFit="cover"
source={{uri: imageSrc.uri}} source={{uri: imageSrc.uri}}
placeholderContentFit="cover" placeholderContentFit="cover"
placeholder={{uri: imageSrc.thumbUri}} placeholder={{uri: imageSrc.thumbUri}}
accessibilityLabel={imageSrc.alt} accessibilityLabel={imageSrc.alt}
onLoad={() => setHasLoaded(false)} onLoad={() => setHasLoaded(false)}
style={imageStyle} style={{flex: 1, borderRadius}}
accessibilityHint="" accessibilityHint=""
accessibilityIgnoresInvertColors accessibilityIgnoresInvertColors
cachePolicy="memory" cachePolicy="memory"
@@ -402,6 +400,7 @@ const ImageItem = ({
</Animated.View> </Animated.View>
</Animated.View> </Animated.View>
</Animated.View> </Animated.View>
</Animated.View>
</GestureDetector> </GestureDetector>
) )
} }
@@ -30,8 +30,6 @@ import {
Transform, Transform,
} from '../../@types' } from '../../@types'
const AnimatedImage = Animated.createAnimatedComponent(Image)
const MAX_ORIGINAL_IMAGE_ZOOM = 2 const MAX_ORIGINAL_IMAGE_ZOOM = 2
const MIN_SCREEN_ZOOM = 2 const MIN_SCREEN_ZOOM = 2
@@ -167,13 +165,9 @@ const ImageItem = ({
} }
}) })
const type = imageSrc.type
const borderRadius =
type === 'circle-avi' ? 1e5 : type === 'rect-avi' ? 20 : 0
const imageStyle = useAnimatedStyle(() => { const imageStyle = useAnimatedStyle(() => {
const {cropContentTransform} = transforms.value const {cropContentTransform} = transforms.value
return { return {
borderRadius,
transform: cropContentTransform, transform: cropContentTransform,
width: '100%', width: '100%',
aspectRatio: imageAspect, aspectRatio: imageAspect,
@@ -195,6 +189,10 @@ const ImageItem = ({
}, },
) )
const type = imageSrc.type
const borderRadius =
type === 'circle-avi' ? 1e5 : type === 'rect-avi' ? 20 : 0
return ( return (
<GestureDetector gesture={composedGesture}> <GestureDetector gesture={composedGesture}>
<Animated.ScrollView <Animated.ScrollView
@@ -213,20 +211,21 @@ const ImageItem = ({
<ActivityIndicator size="small" color="#FFF" style={styles.loading} /> <ActivityIndicator size="small" color="#FFF" style={styles.loading} />
)} )}
<Animated.View style={imageCropStyle}> <Animated.View style={imageCropStyle}>
<AnimatedImage <Animated.View style={imageStyle}>
<Image
contentFit="contain" contentFit="contain"
source={{uri: imageSrc.uri}} source={{uri: imageSrc.uri}}
placeholderContentFit="contain" placeholderContentFit="contain"
placeholder={{uri: imageSrc.thumbUri}} placeholder={{uri: imageSrc.thumbUri}}
style={imageStyle} style={{flex: 1, borderRadius}}
accessibilityLabel={imageSrc.alt} accessibilityLabel={imageSrc.alt}
accessibilityHint="" accessibilityHint=""
enableLiveTextInteraction={showControls && !scaled} enableLiveTextInteraction={showControls && !scaled}
accessibilityIgnoresInvertColors accessibilityIgnoresInvertColors
onLoad={() => setHasLoaded(true)} onLoad={() => setHasLoaded(true)}
cachePolicy="memory-disk"
/> />
</Animated.View> </Animated.View>
</Animated.View>
</Animated.ScrollView> </Animated.ScrollView>
</GestureDetector> </GestureDetector>
) )