Browse Source

fix: silently ignore a verticle animation when no item (#3757)

If when the verticleAnimationFrame callback fires, and the item no longer exists, (it has no parent), then we need to silently ignore that frame
develop
Marais Rossouw 7 years ago
committed by Yotam Berkowitz
parent
commit
9c9f2726dc
3 changed files with 54 additions and 1 deletions
  1. +1
    -1
      lib/timeline/Core.js
  2. +9
    -0
      lib/timeline/Timeline.js
  3. +44
    -0
      test/Timeline.test.js

+ 1
- 1
lib/timeline/Core.js View File

@ -137,7 +137,7 @@ Core.prototype._create = function (container) {
// emitted via emitter
this.hammer = new Hammer(this.dom.root);
var pinchRecognizer = this.hammer.get('pinch').set({enable: true});
hammerUtil.disablePreventDefaultVertically(pinchRecognizer);
pinchRecognizer && hammerUtil.disablePreventDefaultVertically(pinchRecognizer);
this.hammer.get('pan').set({threshold:5, direction: Hammer.DIRECTION_HORIZONTAL});
this.listeners = {};

+ 9
- 0
lib/timeline/Timeline.js View File

@ -448,6 +448,10 @@ Timeline.prototype.focus = function(id, options) {
var verticalAnimationFrame = function(ease, willDraw, done) {
var verticalScroll = getItemVerticalScroll(me, item);
if (verticalScroll === false) {
return; // We don't need to scroll, so do nothing
}
if(!initialVerticalScroll) {
initialVerticalScroll = verticalScroll;
}
@ -560,6 +564,11 @@ function getEnd(item) {
* @return {{shouldScroll: bool, scrollOffset: number, itemTop: number}}
*/
function getItemVerticalScroll(timeline, item) {
if (!item.parent) {
// The item no longer exists, so ignore this focus.
return false;
}
var leftHeight = timeline.props.leftContainer.height;
var contentHeight = timeline.props.left.height;

+ 44
- 0
test/Timeline.test.js View File

@ -0,0 +1,44 @@
var DataSet = require('../lib/DataSet');
var Timeline = require('../lib/timeline/Timeline');
describe('Timeline', function () {
before(function () {
this.jsdom = require('jsdom-global')({
pretendToBeVisual: true
});
global['Element'] = window.Element;
global['requestAnimationFrame'] = function(cb) {
cb();
};
});
after(function () {
this.jsdom();
});
it('should not throw when updating data in close succession', function (done) {
var timeline = new Timeline(document.createElement('div'), []);
var events = [
{start: new Date(), id: 1},
{start: new Date(), id: 2}
];
timeline
.setItems(new DataSet(events));
setTimeout(function() {
timeline
.setItems(new DataSet([
{start: new Date(), id: 3},
{start: new Date(), id: 4},
{start: new Date(), id: 5}
]));
done();
}, 5);
timeline
.setSelection([events[0].id], {animation: false});
});
});

Loading…
Cancel
Save