Skip to content

Commit 78136cc

Browse files
committed
fix #48
1 parent 5333815 commit 78136cc

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
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.3.3",
3+
"version": "2.3.4",
44
"description": "tween-one anim component for react",
55
"keywords": [
66
"react",

src/plugin/StylePlugin.jsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
stylesToCss,
1414
createMatrix,
1515
} from 'style-utils';
16-
import { startConvertToEndUnit, getTransformValue } from '../util.js';
16+
import { startConvertToEndUnit, getTransformValue, styleValueToArray } from '../util.js';
1717
import _plugin from '../plugins';
1818

1919
const StylePlugin = function (target, vars, type) {
@@ -27,14 +27,23 @@ StylePlugin.prototype = {
2727
name: 'style',
2828
};
2929
const p = StylePlugin.prototype;
30-
p.getTweenData = function (key, vars) {
30+
p.getTweenData = function (key, $vars) {
3131
const data = {
3232
data: {},
3333
dataType: {},
3434
dataUnit: {},
3535
dataCount: {},
3636
dataSplitStr: {},
3737
};
38+
let vars = $vars;
39+
if (styleValueToArray[key]) {
40+
vars = vars.toString().split(' ');
41+
vars = vars.map(c => (typeof $vars === 'number' ? `${c}px` : c));
42+
vars[1] = vars[1] || vars[0];
43+
vars[2] = vars[2] || vars[0];
44+
vars[3] = vars[3] || vars[1] || vars[0];
45+
vars = vars.join(' ');
46+
}
3847
if (key.match(/colo|fill|storker/i)) {
3948
data.data[key] = parseColor(vars);
4049
data.dataType[key] = 'color';
@@ -46,7 +55,7 @@ p.getTweenData = function (key, vars) {
4655
data.dataType[key] = 'shadow';
4756
} else if (typeof vars === 'string' && vars.split(/[\s|,]/).length > 1) {
4857
data.data[key] = vars.split(/[\s|,]/);
49-
data.dataSplitStr[key] = vars.replace(/[^\s|,]/g, '');
58+
data.dataSplitStr[key] = vars.replace(/[^\s|,]/g, '').replace(/\s+/g, ' ');
5059
data.dataType[key] = 'string';
5160
} else {
5261
data.data[key] = vars;

src/util.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ export const transformOrFilter = {
1616
'-webkit-filter': 1
1717
};
1818

19+
export const styleValueToArray = {
20+
margin: 1,
21+
padding: 1,
22+
borderWidth: 1,
23+
borderRadius: 1
24+
}
25+
1926
export function toArrayChildren(children) {
2027
const ret = [];
2128
React.Children.forEach(children, (c) => {

tests/tweenOne.spec.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ describe('rc-tween-one', () => {
104104
width: '10vh',
105105
height: '100%',
106106
boxShadow: '0 0 30px rgba(255,125,0,0.5)',
107-
marginLeft: '30rem',
107+
margin: '30rem',
108108
scale: 1.5,
109109
x: '+=100',
110110
transformOrign: '30% 10%',
111111
delay: 100,
112112
yoyo: true,
113113
},
114-
style: { top: 0, left: '10vw', width: '5vh', height: '10%', marginLeft: '10rem' },
114+
style: { top: 0, left: '10vw', width: '5vh', height: '10%', margin: '10rem' },
115115
});
116116
const child = TestUtils.findRenderedDOMComponentWithTag(instance, 'div');
117117
console.log('start:', child.style.top);

0 commit comments

Comments
 (0)