@mr_gain/react-native-image-modal
Version:
image full screen modal for react native
32 lines • 1.12 kB
JavaScript
import { useState } from 'react';
import { Dimensions } from 'react-native';
var useOriginImageLayout = function (_a) {
var imageRef = _a.imageRef, isRTL = _a.isRTL;
var _b = useState({
x: 0,
y: 0,
width: 0,
height: 0,
}), originImageLayout = _b[0], setOriginImageLayout = _b[1];
var getModalPositionX = function (x, width) {
if (isRTL) {
return Dimensions.get('window').width - width - x;
}
return x;
};
var updateOriginImageLayout = function () {
var _a;
(_a = imageRef.current) === null || _a === void 0 ? void 0 : _a.measureInWindow(function (x, y, width, height) {
setOriginImageLayout({
width: width,
height: height,
x: getModalPositionX(x, width),
y: y,
});
});
};
Dimensions.addEventListener('change', updateOriginImageLayout);
return { originImageLayout: originImageLayout, updateOriginImageLayout: updateOriginImageLayout };
};
export { useOriginImageLayout };
//# sourceMappingURL=index.js.map