Skip to content

Commit 160d6e7

Browse files
committed
add willUnmount test and add findDOMNode
1 parent a680f5d commit 160d6e7

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

src/QueueAnim.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class QueueAnim extends React.Component {
160160
// 在出场没结束时,childrenShow 里的值将不会清除。再触发进场时, childrenShow 里的值是保留着的, 设置了 enterForcedRePlay 将重新播放进场。
161161
newChildren.forEach(item => {
162162
if (this.keysToLeave.indexOf(item.key) >= 0) {
163-
const node = this.refs[item.key];
163+
const node = findDOMNode(this.refs[item.key]);
164164
// 因为进场是用的间隔性进入,这里不做 stop 处理将会在这间隔里继续出场的动画。。
165165
velocity(node, 'stop');
166166
delete childrenShow[item.key];

tests/index.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('rc-queue-anim', () => {
4444
getInitialState() {
4545
return {
4646
show: true,
47+
unMount: false,
4748
items: [{
4849
key: 1,
4950
content: 'div',
@@ -61,6 +62,11 @@ describe('rc-queue-anim', () => {
6162
show: !this.state.show,
6263
});
6364
},
65+
unMountQueue() {
66+
this.setState({
67+
unMount: true,
68+
});
69+
},
6470
removeOne() {
6571
const items = this.state.items;
6672
const removeIndex = 0;
@@ -70,14 +76,16 @@ describe('rc-queue-anim', () => {
7076
},
7177
render() {
7278
return (
73-
<QueueAnim {...props}>
74-
{
75-
this.state.show ?
76-
this.state.items.map((item) => <div key={item.key}>{item.content}</div>) :
77-
null
78-
}
79-
{null}
80-
</QueueAnim>
79+
<section>
80+
{!this.state.unMount ? <QueueAnim {...props}>
81+
{
82+
this.state.show ?
83+
this.state.items.map((item) => <div key={item.key}>{item.content}</div>) :
84+
null
85+
}
86+
{null}
87+
</QueueAnim> : null}
88+
</section>
8189
);
8290
},
8391
});
@@ -343,4 +351,23 @@ describe('rc-queue-anim', () => {
343351
}, 17);
344352
}, 1000);
345353
});
354+
355+
it.only('will un mount', (done) => {
356+
const instance = createQueueAnimInstance({
357+
animConfig(e) {
358+
if (e.index === 1) {
359+
return { top: [100, 0] };
360+
}
361+
return { left: [100, 0] };
362+
},
363+
});
364+
setTimeout(() => {
365+
let children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
366+
expect(children.length).to.be(4);
367+
instance.unMountQueue();
368+
children = TestUtils.scryRenderedDOMComponentsWithTag(instance, 'div');
369+
expect(children.length).to.be(0);
370+
done();
371+
}, 100);
372+
});
346373
});

0 commit comments

Comments
 (0)