UNPKG

react-native-zoom-toolkit

Version:

Smoothly zoom any image, video or component you want!

44 lines 1.83 kB
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, { forwardRef } from 'react'; import { CropMode } from '../../components/crop/types'; import { getInvalidChildrenMessage } from '../utils/messages'; export default function withCropValidation(WrappedComponent) { return /*#__PURE__*/forwardRef((props, ref) => { const { mode, minScale, maxScale, children } = props; const childrenCount = React.Children.count(children); if (childrenCount !== 1 && mode === CropMode.MANAGED) { const message = getInvalidChildrenMessage({ name: 'CropZoom', expected: 1, actual: childrenCount }); throw new Error(message); } if (childrenCount !== 0 && mode === CropMode.OVERLAY) { const message = getInvalidChildrenMessage({ name: 'CropZoom', expected: 0, actual: childrenCount }); throw new Error(message); } if (minScale !== undefined && minScale < 1) { throw new Error('minScale property must be greater than or equals one'); } if (maxScale !== undefined && maxScale < 1) { throw new Error('maxScale property must be greater than or equals one'); } if (minScale !== undefined && maxScale !== undefined && minScale > maxScale) { throw new Error('minScale property must not be greater than maxScale'); } return /*#__PURE__*/React.createElement(WrappedComponent, _extends({}, props, { reference: ref })); }); } //# sourceMappingURL=withCropValidation.js.map