Skip to content

Commit aa6535c

Browse files
committed
add enterForcedRePlay
1 parent 212fdba commit aa6535c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/QueueAnim.jsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class QueueAnim extends React.Component {
154154

155155
const childrenShow = this.state.childrenShow;
156156
if (nextProps.enterForcedRePlay) {
157-
// 在出场没结束时,childrenShow 里的值将不会清除。再触发进场时, childrenShow 里的值是保留着的,所以在这做下清除
157+
// 在出场没结束时,childrenShow 里的值将不会清除。再触发进场时, childrenShow 里的值是保留着的, 设置了 enterForcedRePlay 将重新播放进场
158158
newChildren.forEach(item => {
159159
if (this.keysToLeave.indexOf(item.key) >= 0) {
160160
const node = this.refs[item.key];
@@ -256,14 +256,14 @@ class QueueAnim extends React.Component {
256256

257257
getInitAnimType = (node, _data) => {
258258
/*
259-
* 强行结束后,获取当前 dom 里是否有 data 里的 key 值,如果有,出场开始启动为 dom 里的值
260-
* 而不是 animTypes 里的初始值,如果是 初始值将会跳动。
259+
* enterForcedRePlay 为 false 时:
260+
* 强行结束后,获取当前 dom 里是否有 data 里的 key 值,
261+
* 如果有,出场开始启动为 dom 里的值
262+
* 而不是 animTypes 里的初始值,如果是初始值将会跳动。
261263
*/
262264
const data = Object.assign({}, assignChild(_data));
263265
const transformsBase = velocity &&
264266
velocity.prototype.constructor.CSS.Lists.transformsBase || [];
265-
// const setPropertyValue = velocity.prototype.constructor.CSS.setPropertyValue;
266-
// const getUnitType = velocity.prototype.constructor.CSS.Values.getUnitType;
267267
const nodeStyle = node.style;
268268
Object.keys(data).forEach(dataKey => {
269269
if (transformsBase.indexOf(dataKey) >= 0) {
@@ -309,10 +309,15 @@ class QueueAnim extends React.Component {
309309
}
310310
const duration = transformArguments(this.props.duration, key, i)[0];
311311
velocity(node, 'stop');
312-
const data = this.getInitAnimType(node, this.getVelocityEnterConfig(key, i));
312+
const data = this.props.enterForcedRePlay ? this.getVelocityEnterConfig(key, i) :
313+
this.getInitAnimType(node, this.getVelocityEnterConfig(key, i));
314+
if (this.props.enterForcedRePlay) {
315+
node.style.visibility = 'hidden';
316+
}
313317
velocity(node, data, {
314318
duration,
315319
easing: this.getVelocityEasing(key, i)[0],
320+
visibility: 'visible',
316321
begin: this.enterBegin.bind(this, key),
317322
complete: this.enterComplete.bind(this, key),
318323
});
@@ -441,6 +446,7 @@ QueueAnim.propTypes = {
441446
animConfig: funcOrObjectOrArray,
442447
ease: funcOrStringOrArray,
443448
leaveReverse: React.PropTypes.bool,
449+
enterForcedRePlay: React.PropTypes.bool,
444450
animatingClassName: React.PropTypes.array,
445451
};
446452

src/utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ export function assignChild(data) {
9090
if (Array.isArray(data[key])) {
9191
obj[key] = [].concat(data[key]);
9292
return;
93+
} else if (typeof data[key] === 'object') {
94+
obj[key] = Object.assign({}, data[key]);
95+
return;
9396
}
9497
obj[key] = data[key];
9598
return;

0 commit comments

Comments
 (0)