UNPKG

@cantonjs/react-scroll-view

Version:

react scroll component using intersection observer API

54 lines (40 loc) 2.05 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); 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; }; }(); var _util = require('./util'); var _EntryState = require('./EntryState'); var _EntryState2 = _interopRequireDefault(_EntryState); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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 || _util.noop; this.onEnter = onEnter || _util.noop; this.onLeave = onLeave || _util.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 _EntryState2.default(entry, this.debugId); if (this._isIntersecting !== isIntersecting) { this._isIntersecting = isIntersecting; this[isIntersecting ? 'onEnter' : 'onLeave'](entryState); } this._onIntersect(entryState); } }]); return Intersection; }(); exports.default = Intersection;