Skip to content

Commit 18b71f9

Browse files
committed
bump 0.12.0-beta.0
1 parent d8ad64d commit 18b71f9

File tree

5 files changed

+126
-3
lines changed

5 files changed

+126
-3
lines changed

assets/switch.less

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.switch {
2+
height: 400px;
3+
background: #CCC;
4+
& ul {
5+
display: block;
6+
width: 100%;
7+
overflow: hidden;
8+
& li {
9+
list-style: none;
10+
height: 100px;
11+
width: 100px;
12+
float: left;
13+
background: #000;
14+
&:nth-child(2n) {
15+
background: #ff6600;
16+
}
17+
}
18+
}
19+
}

examples/switch.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
placeholder

examples/switch.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* eslint-disable no-console,react/no-multi-comp */
2+
import QueueAnim from 'rc-queue-anim';
3+
import React from 'react';
4+
import ReactDom from 'react-dom';
5+
import '../assets/switch.less';
6+
7+
class Demo extends React.Component {
8+
constructor() {
9+
super(...arguments);
10+
this.childrenKey = [
11+
{ key: 1 },
12+
{ key: 2 },
13+
{ key: 3 },
14+
{ key: 4 },
15+
{ key: 5 },
16+
{ key: 6 },
17+
];
18+
this.state = {
19+
childrenKey: this.childrenKey,
20+
};
21+
}
22+
23+
onEnter = () => {
24+
this.setState({
25+
childrenKey: null,
26+
});
27+
};
28+
29+
onLeave = () => {
30+
this.setState({
31+
childrenKey: this.childrenKey,
32+
});
33+
};
34+
35+
getChildren = () => {
36+
return (this.state.childrenKey || []).map(item => {
37+
return (<li key={item.key} />);
38+
});
39+
};
40+
41+
render() {
42+
const childrenToRender = this.getChildren();
43+
return (<div className="switch" onMouseEnter={this.onEnter} onMouseLeave={this.onLeave}>
44+
<QueueAnim component="ul" leaveReverse delay={[0, 300]} type="scale">
45+
{childrenToRender}
46+
</QueueAnim>
47+
<QueueAnim component="ul" leaveReverse delay={150} type="scale">
48+
{childrenToRender}
49+
</QueueAnim>
50+
<QueueAnim component="ul" leaveReverse delay={[300, 0]} type="scale">
51+
{childrenToRender}
52+
</QueueAnim>
53+
</div>);
54+
}
55+
}
56+
57+
ReactDom.render(<Demo />, document.getElementById('__react-content'));

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": "0.11.12",
3+
"version": "0.12.0-beta.0",
44
"description": "Queue animation component for react",
55
"keywords": [
66
"react",

src/QueueAnim.jsx

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,23 @@ class QueueAnim extends React.Component {
149149
currentChildren,
150150
nextChildren
151151
);
152-
152+
// 在出场没结束时,childrenShow 里的值将不会清除。再触发进场时, childrenShow 里的值是保留着的,所以在这做下清除。
153+
const childrenShow = this.state.childrenShow;
154+
newChildren.forEach(item => {
155+
if (this.keysToLeave.indexOf(item.key) >= 0) {
156+
const node = this.refs[item.key];
157+
// 因为进场是用的间隔性进入,这里不做 stop 处理将会在这间隔里继续出场的动画。。
158+
velocity(node, 'stop');
159+
delete childrenShow[item.key];
160+
}
161+
});
153162
this.keysToEnter = [];
154163
this.keysToLeave = [];
155164
this.keysAnimating = [];
156165

157166
// need render to avoid update
158167
this.setState({
168+
childrenShow,
159169
children: newChildren,
160170
});
161171

@@ -272,6 +282,15 @@ class QueueAnim extends React.Component {
272282
});
273283
}
274284

285+
checkStyleName = (p) => {
286+
const a = ['O', 'Moz', 'ms', 'Ms', 'Webkit'];
287+
if (p !== 'filter' && p in document.body.style) {
288+
return p;
289+
}
290+
const _p = p.charAt(0).toUpperCase() + p.substr(1);
291+
return `${(a.filter((key) => `${key}${_p}` in document.body.style)[0] || '')}${_p}`;
292+
};
293+
275294
performLeave(key, i) {
276295
clearTimeout(this.placeholderTimeoutIds[key]);
277296
delete this.placeholderTimeoutIds[key];
@@ -284,7 +303,34 @@ class QueueAnim extends React.Component {
284303
const duration = transformArguments(this.props.duration, key, i)[1];
285304
const order = this.props.leaveReverse ? (this.keysToLeave.length - i - 1) : i;
286305
velocity(node, 'stop');
287-
velocity(node, this.getVelocityLeaveConfig(key, i), {
306+
/*
307+
* 强行结束后,获取当前 dom 里是否有 data 里的 key 值,如果有,出场开始启动为 dom 里的值
308+
* 而不是 animTypes 里的初始值,如果是 初始值将会跳动。
309+
*/
310+
const data = { ...this.getVelocityLeaveConfig(key, i) };
311+
const transformsBase = velocity &&
312+
velocity.prototype.constructor.CSS.Lists.transformsBase || [];
313+
// const setPropertyValue = velocity.prototype.constructor.CSS.setPropertyValue;
314+
// const getUnitType = velocity.prototype.constructor.CSS.Values.getUnitType;
315+
const nodeStyle = node.style;
316+
Object.keys(data).forEach(dataKey => {
317+
if (transformsBase.indexOf(dataKey) >= 0) {
318+
const transformString = nodeStyle[this.checkStyleName('transform')];
319+
if (transformString && transformString !== 'none') {
320+
if (transformString.match(dataKey)) {
321+
const rep = new RegExp(`[^${dataKey}\\(\\d+.*\\)]`, 'i');
322+
const rep2 = new RegExp(`${dataKey}\\(([\\s\\S]+)\\)`, 'i');
323+
const transformData = transformString.replace(rep, '').replace(rep2, '$1');
324+
data[dataKey][1] = parseFloat(transformData);
325+
return;
326+
}
327+
}
328+
}
329+
if (nodeStyle[dataKey] && parseFloat(nodeStyle[dataKey])) {
330+
data[dataKey][1] = parseFloat(nodeStyle[dataKey]);
331+
}
332+
});
333+
velocity(node, data, {
288334
delay: interval * order + delay,
289335
duration,
290336
easing: this.getVelocityEasing(key, i)[1],

0 commit comments

Comments
 (0)