Add onImageIndexChange callback prop (#20)

This commit is contained in:
Anton Kalinin 2020-02-04 20:38:06 +02:00 committed by GitHub
parent a9aaf80809
commit 96578c9be2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -66,6 +66,7 @@ const [visible, setIsVisible] = useState(false);
| `imageIndex` | Current index of image to display | number | true | | `imageIndex` | Current index of image to display | number | true |
| `visible` | Is modal shown or not | boolean | true | | `visible` | Is modal shown or not | boolean | true |
| `onRequestClose` | Function called to close the modal | function | true | | `onRequestClose` | Function called to close the modal | function | true |
| `onImageIndexChange` | Function called when image index has been changed | function | false |
| `animationType` | Animation modal presented with: default `fade` | `none`, `fade`, `slide` | false | | `animationType` | Animation modal presented with: default `fade` | `none`, `fade`, `slide` | false |
| `backgroundColor` | Background color of the modal in HEX (#000000EE) | string | false | | `backgroundColor` | Background color of the modal in HEX (#000000EE) | string | false |
| `swipeToCloseEnabled` | Close modal with swipe up or down: default `true` | boolean | false | | `swipeToCloseEnabled` | Close modal with swipe up or down: default `true` | boolean | false |

View File

@ -6,7 +6,7 @@
* *
*/ */
import React, { ComponentType, useCallback } from "react"; import React, { ComponentType, useCallback, useEffect } from "react";
import { import {
Animated, Animated,
Dimensions, Dimensions,
@ -29,6 +29,7 @@ type Props = {
imageIndex: number; imageIndex: number;
visible: boolean; visible: boolean;
onRequestClose: () => void; onRequestClose: () => void;
onImageIndexChange?: (imageIndex: number) => void;
animationType?: "none" | "fade" | "slide"; animationType?: "none" | "fade" | "slide";
backgroundColor?: string; backgroundColor?: string;
swipeToCloseEnabled?: boolean; swipeToCloseEnabled?: boolean;
@ -47,6 +48,7 @@ function ImageViewing({
imageIndex, imageIndex,
visible, visible,
onRequestClose, onRequestClose,
onImageIndexChange,
animationType = DEFAULT_ANIMATION_TYPE, animationType = DEFAULT_ANIMATION_TYPE,
backgroundColor = DEFAULT_BG_COLOR, backgroundColor = DEFAULT_BG_COLOR,
swipeToCloseEnabled, swipeToCloseEnabled,
@ -63,6 +65,12 @@ function ImageViewing({
toggleBarsVisible toggleBarsVisible
] = useAnimatedComponents(); ] = useAnimatedComponents();
useEffect(() => {
if (onImageIndexChange) {
onImageIndexChange(currentImageIndex);
}
}, [currentImageIndex]);
const onZoom = useCallback( const onZoom = useCallback(
(isScaled: boolean) => { (isScaled: boolean) => {
// @ts-ignore // @ts-ignore