Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/QueueAnim.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class QueueAnim extends React.Component {
this.keysToEnter = [];
this.keysToLeave = [];
this.keysAnimating = [];
this.placeholderTimeoutIds = {};

// 第一次进入,默认进场
const children = toArrayChildren(getChildrenFromProps(this.props));
Expand Down Expand Up @@ -112,6 +113,9 @@ class QueueAnim extends React.Component {
velocity(findDOMNode(this.refs[child.key]), 'stop');
}
});
Object.keys(this.placeholderTimeoutIds).forEach(key => {
clearTimeout(this.placeholderTimeoutIds[key]);
});
}
}

Expand Down Expand Up @@ -148,19 +152,12 @@ class QueueAnim extends React.Component {
}

performEnter(key, i) {
const placeholderNode = findDOMNode(this.refs[placeholderKeyPrefix + key]);
if (!placeholderNode) {
return;
}
const interval = transformArguments(this.props.interval, key, i)[0];
const delay = transformArguments(this.props.delay, key, i)[0];
placeholderNode.style.visibility = 'hidden';
velocity(placeholderNode, 'stop');
velocity(placeholderNode, {opacity: [0, 0]}, {
delay: interval * i + delay,
duration: 0,
begin: this.performEnterBegin.bind(this, key, i),
});
this.placeholderTimeoutIds[key] = setTimeout(
this.performEnterBegin.bind(this, key, i),
interval * i + delay
);
if (this.keysToEnter.indexOf(key) >= 0) {
this.keysToEnter.splice(this.keysToEnter.indexOf(key), 1);
}
Expand Down Expand Up @@ -190,6 +187,8 @@ class QueueAnim extends React.Component {
}

performLeave(key, i) {
clearTimeout(this.placeholderTimeoutIds[key]);
delete this.placeholderTimeoutIds[key];
const node = findDOMNode(this.refs[key]);
if (!node) {
return;
Expand Down Expand Up @@ -239,7 +238,8 @@ class QueueAnim extends React.Component {
if (this.keysToLeave.indexOf(key) >= 0) {
this.keysToLeave.splice(this.keysToLeave.indexOf(key), 1);
}
if (this.keysToLeave.length === 0) {
const needLeave = this.keysToLeave.some(c => childrenShow[c]);
if (!needLeave) {
const currentChildren = toArrayChildren(getChildrenFromProps(this.props));
this.setState({
children: currentChildren,
Expand Down
94 changes: 52 additions & 42 deletions tests/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ describe('rc-queue-anim', function () {
function shouldAnimatingThisOne(instance, index) {
let children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
children.forEach(function(node, i) {
console.log(i, node.style.visibility, getOpacity(node));
console.log(i, getOpacity(node));
if (i === 0) {
return;
}
if (i <= index) {
expect(node.style.visibility).to.be('visible');
expect(getOpacity(node)).to.above(0);
} else {
expect(node.style.visibility).to.be('hidden');
// placeholder
expect(node.innerHTML).to.be('');
}
});
}
Expand Down Expand Up @@ -191,34 +191,39 @@ describe('rc-queue-anim', function () {
left: [100, 0]
}
});
let children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
expect(isNaN(getLeft(children[1]))).to.be.ok();
setTimeout(function() {
expect(getLeft(children[1])).to.above(0);
done();
}, 10);
let children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
expect(isNaN(getLeft(children[1]))).to.be.ok();
setTimeout(function() {
children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
expect(getLeft(children[1])).to.above(0);
done();
}, 10);
}, 0);
});

it('should support animation when change direction at animating', function(done) {
instance = createQueueAnimInstance({
leaveReverse: true
});
let children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
let index = 0;
let maxOpacity;
let opacityArray = [];
let interval = setInterval(function() {
index += 1;
let opacity = getOpacity(children[1]);
opacityArray.push(opacity);
let opacity = getOpacity(TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div')[1]);
if (!isNaN(opacity)) {
opacityArray.push(opacity);
}
console.log('time: ', index * 30, 'opacity: ', opacity);
if (index === 10) {
instance.toggle();
maxOpacity = opacity;
console.log('toggle');
}
if (opacity >= 1 || opacity <= 0) {
if (opacity >= 1 || opacity <= 0 || isNaN(opacity)) {
clearInterval(interval);
console.log(maxOpacity);
opacityArray.forEach(function(o) {
expect(maxOpacity >= o).to.be.ok();
});
Expand All @@ -230,17 +235,20 @@ describe('rc-queue-anim', function () {
it('should has animating className', function(done) {
const interval = defaultInterval;
instance = createQueueAnimInstance();
let children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
expect(children[1].className).to.contain('queue-anim-entering');
setTimeout(function() {
expect(children[1].className).not.to.contain('queue-anim-entering');
let removeIndex = instance.removeOne();
expect(children[removeIndex + 1].className).to.contain('queue-anim-leaving');
let children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
expect(children[1].className).to.contain('queue-anim-entering');
setTimeout(function() {
expect(children[removeIndex + 1].className).not.to.contain('queue-anim-leaving');
done();
expect(children[1].className).not.to.contain('queue-anim-entering');
let removeIndex = instance.removeOne();
children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
expect(children[removeIndex + 1].className).to.contain('queue-anim-leaving');
setTimeout(function() {
expect(children[removeIndex + 1].className).not.to.contain('queue-anim-leaving');
done();
}, 550);
}, 550);
}, 550);
}, 5);
});

it('should has animating config is func enter', function (done) {
Expand All @@ -253,34 +261,36 @@ describe('rc-queue-anim', function () {
return {left: [100, 0]};
}
});
let children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
expect(isNaN(getLeft(children[1]))).to.be.ok();
expect(isNaN(getTop(children[2]))).to.be.ok();
setTimeout(function () {
children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
expect(getLeft(children[1])).to.above(0);
expect(isNaN(getTop(children[1]))).to.be.ok();
console.log('left:', getLeft(children[1]));
setTimeout(function() {
let children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
expect(isNaN(getLeft(children[1]))).to.be.ok();
expect(isNaN(getTop(children[2]))).to.be.ok();
setTimeout(function () {
children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
expect(getTop(children[2])).to.above(0);
expect(isNaN(getLeft(children[2]))).to.be.ok();
console.log('top:', getTop(children[2]));
expect(getLeft(children[1])).to.above(0);
expect(isNaN(getTop(children[1]))).to.be.ok();
console.log('left:', getLeft(children[1]));
setTimeout(function () {
children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
expect(getTop(children[2])).to.be(100);
expect(getTop(children[2])).to.above(0);
expect(isNaN(getLeft(children[2]))).to.be.ok();
console.log('top_end:', getTop(children[2]));
done();
console.log('top:', getTop(children[2]));
setTimeout(function () {
children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
expect(getTop(children[2])).to.be(100);
expect(isNaN(getLeft(children[2]))).to.be.ok();
console.log('top_end:', getTop(children[2]));
done();
}, 500);
}, interval);
setTimeout(function () {
children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
expect(getLeft(children[1])).to.be(100);
expect(isNaN(getTop(children[1]))).to.be.ok();
console.log('left_end:', getLeft(children[1]));
}, 500);
}, interval);
setTimeout(function () {
children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
expect(getLeft(children[1])).to.be(100);
expect(isNaN(getTop(children[1]))).to.be.ok();
console.log('left_end:', getLeft(children[1]));
}, 500);
}, 10);
}, 10);
}, 0);
});

it('should has animating config is func leave', function (done) {
Expand Down