Skip to content

Commit 8b5d3bf

Browse files
committed
fix in strict mode #119
1 parent 65a0a41 commit 8b5d3bf

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-queue-anim",
3-
"version": "1.8.4",
3+
"version": "1.8.5",
44
"description": "Queue animation component for react",
55
"keywords": [
66
"react",

src/QueueAnim.jsx

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from './utils';
1414
import AnimTypes from './animTypes';
1515

16-
const noop = () => { };
16+
const noop = () => {};
1717

1818
const typeDefault = [
1919
'displayName',
@@ -59,12 +59,14 @@ class QueueAnim extends React.Component {
5959
appear: true,
6060
};
6161

62-
static getDerivedStateFromProps(props, { prevProps, children, childrenShow: prevChildShow, $self }) {
62+
static getDerivedStateFromProps(
63+
props,
64+
{ prevProps, children, childrenShow: prevChildShow, $self },
65+
) {
6366
const nextState = {
6467
prevProps: props,
6568
};
66-
if (prevProps && props !== prevProps
67-
) {
69+
if (prevProps && props !== prevProps) {
6870
const nextChildren = toArrayChildren(props.children).filter(c => c);
6971
let currentChildren = $self.originalChildren.filter(item => item);
7072
if (children.length) {
@@ -75,8 +77,14 @@ class QueueAnim extends React.Component {
7577
const leaveChild = children.filter(
7678
item => item && $self.keysToLeave.indexOf(item.key) >= 0,
7779
);
78-
79-
$self.leaveUnfinishedChild = leaveChild.map(item => item.key);
80+
$self.leaveUnfinishedChild = leaveChild
81+
.map(item => {
82+
if ($self.placeholderTimeoutIds[item.key]) {
83+
return item.key;
84+
}
85+
return null;
86+
})
87+
.filter(c => c);
8088
/**
8189
* 获取 leaveChild 在 state.children 里的序列,再将 leaveChild 和 currentChildren 的重新排序。
8290
* 避逸 state.children 在 leaveComplete 里没全部完成不触发,
@@ -87,7 +95,10 @@ class QueueAnim extends React.Component {
8795
const currentChild = [];
8896
const childReOrder = child => {
8997
child.forEach(item => {
90-
const order = stateChildren.indexOf(item);
98+
const order = stateChildren.findIndex(c => c.key === item.key);
99+
if (currentChild.indexOf(item) !== -1) {
100+
return;
101+
}
91102
// -1 不应该出现的情况,直接插入数组后面.
92103
if (order === -1) {
93104
currentChild.push(item);
@@ -175,11 +186,6 @@ class QueueAnim extends React.Component {
175186
* 记录 TweenOne 标签,在 leaveUnfinishedChild 里使用,残留的元素不需要考虑 props 的变更。
176187
*/
177188
this.saveTweenOneTag = {};
178-
/**
179-
* @param enterAnimation;
180-
* 记录进场的动画, 在没进场完成, 将进场的动画保存,免得重新生成。
181-
*/
182-
this.enterAnimation = {};
183189
/**
184190
* @param childrenShow;
185191
* 记录 animation 里是否需要 startAnim;
@@ -216,7 +222,7 @@ class QueueAnim extends React.Component {
216222
* @param currentRef;
217223
* 记录 component 是组件时的 ref;
218224
*/
219-
this.currentRef = null
225+
this.currentRef = null;
220226
// 第一次进入,默认进场
221227
const children = toArrayChildren(getChildrenFromProps(props));
222228
const childrenShow = {};
@@ -295,8 +301,8 @@ class QueueAnim extends React.Component {
295301
const end = type === 'enter' ? 0 : 1;
296302
const animate = this.getAnimData(props, key, i, enterOrLeave, end);
297303
const startAnim =
298-
type === 'enter' && (props.forcedReplay || !this.childrenShow[key]) ?
299-
this.getAnimData(props, key, i, enterOrLeave, start)
304+
type === 'enter' && (props.forcedReplay || !this.childrenShow[key])
305+
? this.getAnimData(props, key, i, enterOrLeave, start)
300306
: null;
301307
let ease = transformArguments(props.ease, key, i)[enterOrLeave];
302308
const duration = transformArguments(props.duration, key, i)[enterOrLeave];
@@ -372,10 +378,10 @@ class QueueAnim extends React.Component {
372378
*/
373379
return props.animConfig
374380
? this.getTweenAnimConfig(
375-
transformArguments(props.animConfig, key, i)[enterOrLeave],
376-
startOrEnd,
377-
enterOrLeave,
378-
)
381+
transformArguments(props.animConfig, key, i)[enterOrLeave],
382+
startOrEnd,
383+
enterOrLeave,
384+
)
379385
: this.getTweenType(transformArguments(props.type, key, i)[enterOrLeave], startOrEnd);
380386
};
381387

@@ -417,9 +423,9 @@ class QueueAnim extends React.Component {
417423
} else {
418424
// 处理进场;
419425
i = toArrayChildren(children).findIndex(c => c && c.key === key);
420-
ref = (c) => {
426+
ref = c => {
421427
this.childRefs[key] = c && c.currentRef ? c.currentRef : c;
422-
}
428+
};
423429
// appear=false 时,设定 childrenShow 和 tweenToEnter 都为 true, 这里不渲染 animation;
424430
if (this.tweenToEnter[key] && !forcedReplay) {
425431
// 如果是已进入的,将直接返回标签。。
@@ -430,9 +436,9 @@ class QueueAnim extends React.Component {
430436
componentProps: child.props,
431437
ref,
432438
});
433-
} else if (!this.tweenToEnter[key]) {
434-
animation = this.enterAnimation[key] || this.getTweenEnterOrLeaveData(key, i, 0, 'enter');
435-
this.enterAnimation[key] = animation;
439+
}
440+
if (!this.tweenToEnter[key] || forcedReplay) {
441+
animation = this.getTweenEnterOrLeaveData(key, i, 0, 'enter');
436442
}
437443
}
438444
const paused = this.keysToEnterPaused[key] && this.keysToLeave.indexOf(key) === -1;
@@ -483,7 +489,7 @@ class QueueAnim extends React.Component {
483489
elem.className = `${elem.className} ${animatingClassName[0]}`.trim();
484490
}
485491
this.childrenShow[key] = true;
486-
}
492+
};
487493

488494
enterComplete = (key, e) => {
489495
if (this.keysToEnterPaused[key] || this.keysToLeave.indexOf(key) >= 0) {
@@ -492,7 +498,6 @@ class QueueAnim extends React.Component {
492498
const elem = e.target;
493499
elem.className = elem.className.replace(this.props.animatingClassName[0], '').trim();
494500
this.tweenToEnter[key] = true;
495-
delete this.enterAnimation[key];
496501
this.props.onEnd({ key, type: 'enter', target: elem });
497502
};
498503

@@ -555,7 +560,9 @@ class QueueAnim extends React.Component {
555560
const props = {
556561
...tagProps,
557562
...this.props.componentProps,
558-
ref: (c) => { this.currentRef = c; }
563+
ref: c => {
564+
this.currentRef = c;
565+
},
559566
};
560567
return createElement(this.props.component, props, childrenToRender);
561568
}

0 commit comments

Comments
 (0)