Add onImageIndexChange callback prop (#20)
This commit is contained in:
parent
a9aaf80809
commit
96578c9be2
|
@ -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 |
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue