react-native-gallery-preview
Version:
<div> <img align="right" height="720" src="example.gif"> </div>
53 lines (52 loc) • 1.54 kB
JavaScript
;
import React, { memo, useCallback, useMemo, useState } from "react";
import { GestureItemComponent } from "../GestureItemComponent/GestureItemComponent";
import { jsx as _jsx } from "react/jsx-runtime";
export const GalleryImageItem = /*#__PURE__*/memo(({
item,
width,
height,
ImageComponent,
...props
}) => {
const [imageDimensions, setImageDimensions] = useState({
width: width,
height: height
});
const contentContainerSize = useMemo(() => {
if (height > width) {
return {
width: width,
height: imageDimensions.height * width / imageDimensions.width
};
}
return {
width: imageDimensions.width * height / imageDimensions.height,
height: height
};
}, [width, height, imageDimensions.height, imageDimensions.width]);
const contentCenter = useMemo(() => ({
contentCenterX: contentContainerSize.width / 2,
contentCenterY: contentContainerSize.height / 2
}), [contentContainerSize]);
const onLoad = useCallback((w, h) => {
setImageDimensions({
width: w,
height: h
});
}, []);
return /*#__PURE__*/_jsx(GestureItemComponent, {
contentCenterX: contentCenter.contentCenterX,
contentCenterY: contentCenter.contentCenterY,
contentContainerSize: contentContainerSize,
width: width,
height: height,
...props,
children: /*#__PURE__*/_jsx(ImageComponent, {
source: item,
onLoad: onLoad,
style: contentContainerSize
})
});
});
//# sourceMappingURL=GalleryImageItem.js.map