UNPKG

@cantonjs/react-scroll-view

Version:

react scroll component using intersection observer API

43 lines (34 loc) 1.78 kB
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } import { noop } from './util'; import EntryState from './EntryState'; var Intersection = function () { function Intersection(_ref) { var onEnter = _ref.onEnter, onLeave = _ref.onLeave, onIntersect = _ref.onIntersect, _ref$debugId = _ref.debugId, debugId = _ref$debugId === undefined ? '' : _ref$debugId; _classCallCheck(this, Intersection); this._onIntersect = onIntersect || noop; this.onEnter = onEnter || noop; this.onLeave = onLeave || noop; this._isIntersecting = false; this.debugId = debugId; // useful for debug } _createClass(Intersection, [{ key: 'onIntersect', value: function onIntersect(eventData) { var entry = eventData.entry; var isIntersecting = entry.isIntersecting; var entryState = new EntryState(entry, this.debugId); if (this._isIntersecting !== isIntersecting) { this._isIntersecting = isIntersecting; this[isIntersecting ? 'onEnter' : 'onLeave'](entryState); } this._onIntersect(entryState); } }]); return Intersection; }(); export default Intersection;