@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
45 lines (44 loc) • 1.92 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import * as React from 'react';
import { get } from 'lodash';
import BasicComponent from '../../../components/Base/BasicComponent';
var ViewPortWatcher = /** @class */ (function (_super) {
__extends(ViewPortWatcher, _super);
function ViewPortWatcher() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.io = new IntersectionObserver(function (entries) {
var onChange = _this.props.onChange;
if (!onChange || entries.length < 1) {
return;
}
// 由于未知原因entries可能会出现多个的情况,因此这里改成取最后一个
var isIntersecting = get(entries[entries.length - 1], 'isIntersecting') || false;
onChange(isIntersecting);
});
return _this;
}
ViewPortWatcher.prototype.componentDidMount = function () {
var _this = this;
this.io.observe(this.getRootDOM());
this.addDisposer(function () {
_this.io.disconnect();
});
};
ViewPortWatcher.prototype.render = function () {
return (React.createElement("div", { className: this.props.className, ref: this.setRootRef }, this.props.children));
};
return ViewPortWatcher;
}(BasicComponent));
export default ViewPortWatcher;