@antmjs/vantui
Version:
一套适用于Taro3及React的vantui组件库
41 lines • 1.44 kB
JavaScript
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { useRef } from 'react';
import { usePersistFn } from '../hooks';
import { queryElementSize } from '../utils/element';
export var useForceResize = function useForceResize(query, onResize) {
var sizeRef = useRef({
width: 0,
height: 0
});
var forceResize = usePersistFn( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
var _yield$queryElementSi, width, height, newSize;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return queryElementSize(query);
case 2:
_yield$queryElementSi = _context.sent;
width = _yield$queryElementSi.width;
height = _yield$queryElementSi.height;
if (!(width === sizeRef.current.width && height === sizeRef.current.height)) {
_context.next = 7;
break;
}
return _context.abrupt("return");
case 7:
newSize = {
width: width,
height: height
};
sizeRef.current = newSize;
onResize(newSize);
case 10:
case "end":
return _context.stop();
}
}, _callee);
})));
return forceResize;
};