first commit
This commit is contained in:
50
frontend/node_modules/rc-virtual-list/lib/hooks/useOriginScroll.js
generated
vendored
Normal file
50
frontend/node_modules/rc-virtual-list/lib/hooks/useOriginScroll.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _react = require("react");
|
||||
var _default = exports.default = function _default(isScrollAtTop, isScrollAtBottom, isScrollAtLeft, isScrollAtRight) {
|
||||
// Do lock for a wheel when scrolling
|
||||
var lockRef = (0, _react.useRef)(false);
|
||||
var lockTimeoutRef = (0, _react.useRef)(null);
|
||||
function lockScroll() {
|
||||
clearTimeout(lockTimeoutRef.current);
|
||||
lockRef.current = true;
|
||||
lockTimeoutRef.current = setTimeout(function () {
|
||||
lockRef.current = false;
|
||||
}, 50);
|
||||
}
|
||||
|
||||
// Pass to ref since global add is in closure
|
||||
var scrollPingRef = (0, _react.useRef)({
|
||||
top: isScrollAtTop,
|
||||
bottom: isScrollAtBottom,
|
||||
left: isScrollAtLeft,
|
||||
right: isScrollAtRight
|
||||
});
|
||||
scrollPingRef.current.top = isScrollAtTop;
|
||||
scrollPingRef.current.bottom = isScrollAtBottom;
|
||||
scrollPingRef.current.left = isScrollAtLeft;
|
||||
scrollPingRef.current.right = isScrollAtRight;
|
||||
return function (isHorizontal, delta) {
|
||||
var smoothOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
||||
var originScroll = isHorizontal ?
|
||||
// Pass origin wheel when on the left
|
||||
delta < 0 && scrollPingRef.current.left ||
|
||||
// Pass origin wheel when on the right
|
||||
delta > 0 && scrollPingRef.current.right // Pass origin wheel when on the top
|
||||
: delta < 0 && scrollPingRef.current.top ||
|
||||
// Pass origin wheel when on the bottom
|
||||
delta > 0 && scrollPingRef.current.bottom;
|
||||
if (smoothOffset && originScroll) {
|
||||
// No need lock anymore when it's smooth offset from touchMove interval
|
||||
clearTimeout(lockTimeoutRef.current);
|
||||
lockRef.current = false;
|
||||
} else if (!originScroll || lockRef.current) {
|
||||
lockScroll();
|
||||
}
|
||||
return !lockRef.current && originScroll;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user