Skip to content

Commit 7d14182

Browse files
committed
update objectEqual, fix bezier scale simultaneous use
1 parent 3561db1 commit 7d14182

File tree

4 files changed

+53
-63
lines changed

4 files changed

+53
-63
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-tween-one",
3-
"version": "2.6.5",
3+
"version": "2.6.6",
44
"description": "tween-one anim component for react",
55
"keywords": [
66
"react",

src/TweenOne.jsx

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -314,48 +314,49 @@ class TweenOne extends Component {
314314
}
315315

316316
render() {
317-
const props = { ...this.props };
318-
[
319-
'animation',
320-
'component',
321-
'componentProps',
322-
'reverseDelay',
323-
'attr',
324-
'paused',
325-
'reverse',
326-
'repeat',
327-
'yoyo',
328-
'moment',
329-
'resetStyle',
330-
'forcedJudg',
331-
].forEach(key => delete props[key]);
332-
props.style = { ...this.props.style };
333-
Object.keys(props.style).forEach(p => {
317+
const {
318+
animation,
319+
component,
320+
componentProps,
321+
reverseDelay,
322+
attr,
323+
paused,
324+
reverse,
325+
repeat,
326+
yoyo,
327+
moment,
328+
resetStyle,
329+
forcedJudg,
330+
children,
331+
...props
332+
} = this.props;
333+
Object.keys(props.style || {}).forEach(p => {
334334
if (p.match(/filter/i)) {
335335
['Webkit', 'Moz', 'Ms', 'ms'].forEach(prefix => {
336336
props.style[`${prefix}Filter`] = props.style[p];
337337
});
338338
}
339339
});
340340
// component 为空时调用子级的。。
341-
if (!this.props.component) {
342-
if (!this.props.children) {
343-
return this.props.children;
341+
const { className } = props;
342+
if (!component && typeof children !== 'string') {
343+
if (!children) {
344+
return children;
344345
}
345-
const childrenProps = this.props.children.props;
346-
const { style, className } = childrenProps;
346+
const childrenProps = children.props;
347+
const { style: childStyle, className: childClass } = childrenProps || {};
347348
// 合并 style 与 className。
348-
const newStyle = { ...style, ...props.style };
349-
const newClassName = props.className ? `${props.className} ${className}` : className;
350-
return React.cloneElement(this.props.children, { style: newStyle, className: newClassName });
349+
const newStyle = { ...childStyle, ...props.style };
350+
const newClassName = className ? `${className} ${childClass}` : childClass;
351+
return React.cloneElement(children, { style: newStyle, className: newClassName });
351352
}
352-
return React.createElement(this.props.component, {
353+
return React.createElement(component, {
353354
ref: (c) => {
354355
this.currentRef = c;
355356
},
356357
...props,
357-
...this.props.componentProps
358-
});
358+
...componentProps
359+
}, children);
359360
}
360361
}
361362
TweenOne.isTweenOne = true;

src/plugin/BezierPlugin.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import {
77
checkStyleName,
88
createMatrix,
9+
getTransform,
910
} from 'style-utils';
1011
const _RAD2DEG = 180 / Math.PI;
1112
const _r1 = [];
@@ -508,7 +509,7 @@ Bezier.prototype = {
508509
this.init();
509510
},
510511
setRatio(r, t, computedStyle) {
511-
t.style.transform = this.set(r);
512+
t.style.transform = getTransform(this.set(r));
512513
if (computedStyle) {
513514
computedStyle.transformSVG = createMatrix(t.style.transform).toString();
514515
}

src/util.js

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ function deepEql(a, b) {
5252
let aa = a[key];
5353
let bb = b[key];
5454
if (Array.isArray(aa) && Array.isArray(bb)) {
55-
aa = aa.join();
56-
bb = bb.join();
55+
const aaa = aa.join();
56+
const bbb = bb.join();
57+
if (aaa === bbb && !aaa.match(/\[object object\]/ig)) {
58+
aa = aaa;
59+
bb = bbb;
60+
}
5761
}
5862
return aa !== bb;
5963
});
@@ -65,38 +69,14 @@ export function objectEqual(obj1, obj2) {
6569
if (obj1 === obj2 || deepEql(obj1, obj2)) {
6670
return true;
6771
}
68-
if (!obj1 || !obj2) {
72+
if (!obj1 || !obj2 || Object.keys(obj1).length !== Object.keys(obj2).length) {
6973
return false;
7074
}
7175
// animation 写在标签上的进行判断是否相等, 判断每个参数有没有 function;
7276
let equalBool = true;
73-
if (Array.isArray(obj1) && Array.isArray(obj2)) {
74-
if (obj1.length !== obj2.length) {
75-
return false;
76-
}
77-
for (let i = 0; i < obj1.length; i++) {
78-
const currentObj = obj1[i];
79-
const nextObj = obj2[i];
80-
for (const p in currentObj) { // eslint-disable-line no-restricted-syntax
81-
if (currentObj[p] !== nextObj[p]) {
82-
if (typeof currentObj[p] === 'object' && typeof nextObj[p] === 'object') {
83-
equalBool = objectEqual(currentObj[p], nextObj[p]);
84-
} else if (typeof currentObj[p] === 'function' && typeof nextObj[p] === 'function') {
85-
if (currentObj[p].name !== nextObj[p].name) {
86-
equalBool = false;
87-
}
88-
} else {
89-
equalBool = false;
90-
}
91-
if (!equalBool) {
92-
return false;
93-
}
94-
}
95-
}
96-
}
97-
}
98-
99-
const setEqualBool = (objA, objB) => {
77+
const setEqualBool = ($a, $b) => {
78+
const objA = Object.keys($a).length > Object.keys($b).length ? $a : $b;
79+
const objB = Object.keys($a).length > Object.keys($b).length ? $b : $a;
10080
Object.keys(objA).forEach(key => {
10181
// 如果前面有参数匹配不相同则直接返回;
10282
if (!equalBool) {
@@ -109,7 +89,7 @@ export function objectEqual(obj1, obj2) {
10989
if (typeof objA[key] === 'object' && typeof objB[key] === 'object') {
11090
equalBool = objectEqual(objA[key], objB[key]);
11191
} else if (typeof objA[key] === 'function' && typeof objB[key] === 'function') {
112-
if (objA[key].name !== objB[key].name) {
92+
if (objA[key].toString().replace(/\s+/g, '') !== objB[key].toString().replace(/\s+/g, '')) {
11393
equalBool = false;
11494
}
11595
} else if (objA[key] !== objB[key]) {
@@ -118,8 +98,16 @@ export function objectEqual(obj1, obj2) {
11898
});
11999
};
120100

121-
setEqualBool(obj1, obj2);
122-
setEqualBool(obj2, obj1);
101+
if (Array.isArray(obj1) && Array.isArray(obj2)) {
102+
if (obj1.length !== obj2.length) {
103+
return false;
104+
}
105+
obj1.forEach((item, i) => {
106+
setEqualBool(item, obj2[i]);
107+
});
108+
} else {
109+
setEqualBool(obj1, obj2);
110+
}
123111
return equalBool;
124112
}
125113

0 commit comments

Comments
 (0)