fix prefetching lightbox images (#1163)
* fix prefetching lightbox images * use array signature * fix other RN native image usage * delay prefetching to allow UI to re-renderzio/stable
parent
77178844fd
commit
331c506728
|
@ -17,6 +17,7 @@ import {
|
||||||
NativeSyntheticEvent,
|
NativeSyntheticEvent,
|
||||||
NativeMethodsMixin,
|
NativeMethodsMixin,
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
|
import {Image} from 'expo-image'
|
||||||
|
|
||||||
import useImageDimensions from '../../hooks/useImageDimensions'
|
import useImageDimensions from '../../hooks/useImageDimensions'
|
||||||
import usePanResponder from '../../hooks/usePanResponder'
|
import usePanResponder from '../../hooks/usePanResponder'
|
||||||
|
@ -41,6 +42,8 @@ type Props = {
|
||||||
doubleTapToZoomEnabled?: boolean
|
doubleTapToZoomEnabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const AnimatedImage = Animated.createAnimatedComponent(Image)
|
||||||
|
|
||||||
const ImageItem = ({
|
const ImageItem = ({
|
||||||
imageSrc,
|
imageSrc,
|
||||||
onZoom,
|
onZoom,
|
||||||
|
@ -128,7 +131,7 @@ const ImageItem = ({
|
||||||
onScroll,
|
onScroll,
|
||||||
onScrollEndDrag,
|
onScrollEndDrag,
|
||||||
})}>
|
})}>
|
||||||
<Animated.Image
|
<AnimatedImage
|
||||||
{...panHandlers}
|
{...panHandlers}
|
||||||
source={imageSrc}
|
source={imageSrc}
|
||||||
style={imageStylesWithOpacity}
|
style={imageStylesWithOpacity}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {
|
||||||
NativeSyntheticEvent,
|
NativeSyntheticEvent,
|
||||||
TouchableWithoutFeedback,
|
TouchableWithoutFeedback,
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
|
import {Image} from 'expo-image'
|
||||||
|
|
||||||
import useDoubleTapToZoom from '../../hooks/useDoubleTapToZoom'
|
import useDoubleTapToZoom from '../../hooks/useDoubleTapToZoom'
|
||||||
import useImageDimensions from '../../hooks/useImageDimensions'
|
import useImageDimensions from '../../hooks/useImageDimensions'
|
||||||
|
@ -42,6 +43,8 @@ type Props = {
|
||||||
doubleTapToZoomEnabled?: boolean
|
doubleTapToZoomEnabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const AnimatedImage = Animated.createAnimatedComponent(Image)
|
||||||
|
|
||||||
const ImageItem = ({
|
const ImageItem = ({
|
||||||
imageSrc,
|
imageSrc,
|
||||||
onZoom,
|
onZoom,
|
||||||
|
@ -131,7 +134,7 @@ const ImageItem = ({
|
||||||
accessibilityRole="image"
|
accessibilityRole="image"
|
||||||
accessibilityLabel={imageSrc.alt}
|
accessibilityLabel={imageSrc.alt}
|
||||||
accessibilityHint="">
|
accessibilityHint="">
|
||||||
<Animated.Image
|
<AnimatedImage
|
||||||
source={imageSrc}
|
source={imageSrc}
|
||||||
style={imageStylesWithOpacity}
|
style={imageStylesWithOpacity}
|
||||||
onLoad={() => setLoaded(true)}
|
onLoad={() => setLoaded(true)}
|
||||||
|
|
|
@ -4,9 +4,10 @@ import {
|
||||||
StyleProp,
|
StyleProp,
|
||||||
View,
|
View,
|
||||||
ViewStyle,
|
ViewStyle,
|
||||||
Image as RNImage,
|
|
||||||
Text,
|
Text,
|
||||||
|
InteractionManager,
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
|
import {Image} from 'expo-image'
|
||||||
import {
|
import {
|
||||||
AppBskyEmbedImages,
|
AppBskyEmbedImages,
|
||||||
AppBskyEmbedExternal,
|
AppBskyEmbedExternal,
|
||||||
|
@ -95,14 +96,9 @@ export function PostEmbeds({
|
||||||
const openLightbox = (index: number) => {
|
const openLightbox = (index: number) => {
|
||||||
store.shell.openLightbox(new ImagesLightbox(items, index))
|
store.shell.openLightbox(new ImagesLightbox(items, index))
|
||||||
}
|
}
|
||||||
const onPressIn = (index: number) => {
|
const onPressIn = (_: number) => {
|
||||||
const firstImageToShow = items[index].uri
|
InteractionManager.runAfterInteractions(() => {
|
||||||
RNImage.prefetch(firstImageToShow)
|
Image.prefetch(items.map(i => i.uri))
|
||||||
items.forEach(item => {
|
|
||||||
if (firstImageToShow !== item.uri) {
|
|
||||||
// First image already prefetched above
|
|
||||||
RNImage.prefetch(item.uri)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue