react-native-zoom-toolkit
Version:
Smoothly zoom any image, video or component you want!
37 lines • 1.72 kB
JavaScript
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React from 'react';
import { forwardRef } from 'react';
import { getInvalidChildrenMessage } from '../utils/messages';
export default function withResumableValidation(Component) {
return /*#__PURE__*/forwardRef((props, ref) => {
const {
minScale,
maxScale,
children
} = props;
const expectedChildren = 1;
const childrenCount = React.Children.count(children);
if (childrenCount !== expectedChildren) {
const message = getInvalidChildrenMessage({
name: 'ResumableZoom',
expected: expectedChildren,
actual: childrenCount
});
throw new Error(message);
}
if (minScale !== undefined && minScale < 1) {
throw new Error('minScale must be greater than or equals one');
}
const isMaxScaleNumber = typeof maxScale === 'number';
if (maxScale !== undefined && isMaxScaleNumber && maxScale < 1) {
throw new Error('maxScale must be greater than one, or a size vector object in order to infer the max scale');
}
if (minScale !== undefined && maxScale !== undefined && isMaxScaleNumber && minScale > maxScale) {
throw new Error('minScale must not be greater than or equals maxScale');
}
return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
reference: ref
}));
});
}
//# sourceMappingURL=withResumableValidation.js.map