diff --git a/ui/v2.5/src/hooks/Lightbox/Lightbox.tsx b/ui/v2.5/src/hooks/Lightbox/Lightbox.tsx index 6a7c8fc3e..23552f745 100644 --- a/ui/v2.5/src/hooks/Lightbox/Lightbox.tsx +++ b/ui/v2.5/src/hooks/Lightbox/Lightbox.tsx @@ -1,4 +1,11 @@ -import React, { useCallback, useEffect, useRef, useState } from "react"; +import React, { + ForwardedRef, + forwardRef, + useCallback, + useEffect, + useRef, + useState, +} from "react"; import { Button, Col, @@ -83,6 +90,84 @@ const MIN_ZOOM = 0.1; const SCROLL_ZOOM_TIMEOUT = 250; const ZOOM_NONE_EPSILON = 0.015; +interface ILightboxCarouselProps { + instantTransition: boolean; + currentIndex: number; + images: ILightboxImage[]; + displayMode: GQL.ImageLightboxDisplayMode; + lightboxSettings: GQL.ConfigImageLightboxInput | undefined; + resetPosition?: boolean; + zoom: number; + scrollAttemptsBeforeChange: number; + firstScroll: React.MutableRefObject; + inScrollGroup: React.MutableRefObject; + movingLeft: boolean; + updateZoom: (v: number) => void; + debouncedScrollReset: () => void; + handleLeft: () => void; + handleRight: () => void; +} + +const LightboxCarousel = forwardRef(function ( + { + instantTransition, + currentIndex, + images, + displayMode, + lightboxSettings, + resetPosition, + zoom, + scrollAttemptsBeforeChange, + firstScroll, + inScrollGroup, + movingLeft, + updateZoom, + debouncedScrollReset, + handleLeft, + handleRight, + }: ILightboxCarouselProps, + carouselRef: ForwardedRef +) { + return ( +
+ {images.map((image, i) => ( +
+ {i >= currentIndex - 1 && i <= currentIndex + 1 ? ( + + ) : undefined} +
+ ))} +
+ ); +}); + interface IProps { images: ILightboxImage[]; isVisible: boolean; @@ -145,7 +230,6 @@ export const LightboxComponent: React.FC = ({ const containerRef = useRef(null); const overlayTarget = useRef(null); - const carouselRef = useRef(null); const indicatorRef = useRef(null); const navRef = useRef(null); const clearIntervalCallback = useRef<() => void>(); @@ -849,48 +933,23 @@ export const LightboxComponent: React.FC = ({ )} - -
- {images.map((image, i) => ( -
- {i >= currentIndex - 1 && i <= currentIndex + 1 ? ( - - ) : undefined} -
- ))} -
- + {allowNavigation && (