first commit
This commit is contained in:
36
frontend/node_modules/@rc-component/trigger/es/hooks/useWatch.js
generated
vendored
Normal file
36
frontend/node_modules/@rc-component/trigger/es/hooks/useWatch.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
||||
import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
|
||||
import { collectScroller, getWin } from "../util";
|
||||
export default function useWatch(open, target, popup, onAlign, onScroll) {
|
||||
useLayoutEffect(function () {
|
||||
if (open && target && popup) {
|
||||
var targetElement = target;
|
||||
var popupElement = popup;
|
||||
var targetScrollList = collectScroller(targetElement);
|
||||
var popupScrollList = collectScroller(popupElement);
|
||||
var win = getWin(popupElement);
|
||||
var mergedList = new Set([win].concat(_toConsumableArray(targetScrollList), _toConsumableArray(popupScrollList)));
|
||||
function notifyScroll() {
|
||||
onAlign();
|
||||
onScroll();
|
||||
}
|
||||
mergedList.forEach(function (scroller) {
|
||||
scroller.addEventListener('scroll', notifyScroll, {
|
||||
passive: true
|
||||
});
|
||||
});
|
||||
win.addEventListener('resize', notifyScroll, {
|
||||
passive: true
|
||||
});
|
||||
|
||||
// First time always do align
|
||||
onAlign();
|
||||
return function () {
|
||||
mergedList.forEach(function (scroller) {
|
||||
scroller.removeEventListener('scroll', notifyScroll);
|
||||
win.removeEventListener('resize', notifyScroll);
|
||||
});
|
||||
};
|
||||
}
|
||||
}, [open, target, popup]);
|
||||
}
|
||||
Reference in New Issue
Block a user