From d47ff542dafdb691fd492845db956dd629122a9b Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 10 Oct 2023 19:07:21 +0100 Subject: Drive-by lightbox refactors (#1659) * Remove dead code from lightbox * Rename imageIndex prop to initialImageIndex * Rename currentImageIndex to imageIndex --- src/view/com/lightbox/ImageViewing/index.tsx | 32 +++++++++++----------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'src/view/com/lightbox/ImageViewing/index.tsx') diff --git a/src/view/com/lightbox/ImageViewing/index.tsx b/src/view/com/lightbox/ImageViewing/index.tsx index b6b321c4a..248f1cebe 100644 --- a/src/view/com/lightbox/ImageViewing/index.tsx +++ b/src/view/com/lightbox/ImageViewing/index.tsx @@ -38,8 +38,7 @@ import {Edge, SafeAreaView} from 'react-native-safe-area-context' type Props = { images: ImageSource[] - keyExtractor?: (imageSrc: ImageSource, index: number) => string - imageIndex: number + initialImageIndex: number visible: boolean onRequestClose: () => void presentationStyle?: ModalProps['presentationStyle'] @@ -60,8 +59,7 @@ const ANIMATION_CONFIG = { function ImageViewing({ images, - keyExtractor, - imageIndex, + initialImageIndex, visible, onRequestClose, backgroundColor = DEFAULT_BG_COLOR, @@ -71,7 +69,7 @@ function ImageViewing({ const imageList = useRef>(null) const [isScaled, setIsScaled] = useState(false) const [isDragging, setIsDragging] = useState(false) - const [currentImageIndex, setImageIndex] = useState(imageIndex) + const [imageIndex, setImageIndex] = useState(initialImageIndex) const [headerTranslate] = useState( () => new Animated.ValueXY(INITIAL_POSITION), ) @@ -125,10 +123,13 @@ function ImageViewing({ }, []) const onLayout = useCallback(() => { - if (imageIndex) { - imageList.current?.scrollToIndex({index: imageIndex, animated: false}) + if (initialImageIndex) { + imageList.current?.scrollToIndex({ + index: initialImageIndex, + animated: false, + }) } - }, [imageList, imageIndex]) + }, [imageList, initialImageIndex]) // This is a hack. // RNGH doesn't have an easy way to express that pinch of individual items @@ -159,7 +160,7 @@ function ImageViewing({ {typeof HeaderComponent !== 'undefined' ? ( React.createElement(HeaderComponent, { - imageIndex: currentImageIndex, + imageIndex, }) ) : ( @@ -205,19 +206,12 @@ function ImageViewing({ setIsScaled(false) onScroll(e) }} - //@ts-ignore - keyExtractor={(imageSrc, index) => - keyExtractor - ? keyExtractor(imageSrc, index) - : typeof imageSrc === 'number' - ? `${imageSrc}` - : imageSrc.uri - } + keyExtractor={imageSrc => imageSrc.uri} /> {typeof FooterComponent !== 'undefined' && ( {React.createElement(FooterComponent, { - imageIndex: currentImageIndex, + imageIndex, })} )} @@ -250,7 +244,7 @@ const styles = StyleSheet.create({ }) const EnhancedImageViewing = (props: Props) => ( - + ) export default EnhancedImageViewing -- cgit 1.4.1