Scroll to next image using lightbox (#2403)

* Scroll at end of image goes to next/previous
* Align bottom image when moving left
This commit is contained in:
WithoutPants
2022-03-22 11:00:32 +11:00
committed by GitHub
parent 5eee305a33
commit 228e8c9bfd
3 changed files with 71 additions and 17 deletions

View File

@@ -89,6 +89,7 @@ export const LightboxComponent: React.FC<IProps> = ({
const [updateImage] = useImageUpdate();
const [index, setIndex] = useState<number | null>(null);
const [movingLeft, setMovingLeft] = useState(false);
const oldIndex = useRef<number | null>(null);
const [instantTransition, setInstantTransition] = useState(false);
const [isSwitchingPage, setIsSwitchingPage] = useState(true);
@@ -261,6 +262,8 @@ export const LightboxComponent: React.FC<IProps> = ({
(isUserAction = true) => {
if (isSwitchingPage || index === -1) return;
setMovingLeft(true);
if (index === 0) {
// go to next page, or loop back if no callback is set
if (pageCallback) {
@@ -281,6 +284,8 @@ export const LightboxComponent: React.FC<IProps> = ({
(isUserAction = true) => {
if (isSwitchingPage) return;
setMovingLeft(false);
if (index === images.length - 1) {
// go to preview page, or loop back if no callback is set
if (pageCallback) {
@@ -685,6 +690,7 @@ export const LightboxComponent: React.FC<IProps> = ({
scrollMode={scrollMode}
onLeft={handleLeft}
onRight={handleRight}
alignBottom={movingLeft}
zoom={i === currentIndex ? zoom : 1}
setZoom={(v) => setZoom(v)}
resetPosition={resetPosition}