Skip to content

Commit e611c9b

Browse files
committed
fix test
1 parent bd20bfe commit e611c9b

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

examples/scrollAnim.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,23 @@ import Tween from 'rc-tween-one';
22
import React from 'react';
33
import ReactDom from 'react-dom';
44
import ScrollOverPack from 'rc-scroll-anim/lib/ScrollOverPack';
5+
import { Row, Col } from 'antd';
56

67
function Demo() {
78
return (
89
<div>
910
<div style={{ height: 800 }}>往下滚动</div>
1011
<ScrollOverPack
1112
style={{ height: 800 }}
13+
component={Row}
14+
componentProps={{ gutter: { md: 12, sm: 5 } }}
1215
>
1316
<Tween
1417
key="1"
1518
animation={{ y: 30, type: 'from', ease: 'easeOutQuart', opacity: 0 }}
1619
reverseDelay={200}
1720
style={{ background: '#fff000' }}
18-
>
19-
执行动画
20-
</Tween>
21-
<Tween
22-
key="2"
23-
id="12"
24-
animation={{ y: 30, delay: 100, ease: 'easeOutQuart', type: 'from', opacity: 0, id: 12 }}
25-
reverseDelay={100}
26-
style={{ background: '#000fff' }}
21+
component={Col}
2722
>
2823
执行动画
2924
</Tween>

examples/simple.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ class Demo extends React.Component {
1010

1111
render() {
1212
return (<Tween
13-
animation={{ x: 300 }}
14-
onChange={this.bbb}
13+
animation={{ x: 300, duration: 100000 }}
1514
style={{ opacity: 1, height: 100, display: 'inline-block' }}
1615
>
1716
<div>执行动效</div>

src/Tween.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -392,20 +392,25 @@ p.resetAnimData = function () {
392392
this.start = {};
393393
};
394394

395-
p.getDefaultStyle = function (domStyle) {
395+
const getDefaultStyle = function (domStyle, defaultStyle, tweenData) {
396396
const $data = defaultData({}, 0);
397397
const getStyleToArray = (styleString) => (
398398
styleString.split(';').filter(c => c).map(str =>
399399
str.split(':').map(s => s.trim())
400400
)
401401
);
402-
const styleToArray = getStyleToArray(this.startDefaultData.style);
402+
const styleToArray = getStyleToArray(defaultStyle);
403403
let domStyleToArray = getStyleToArray(domStyle);
404-
this.data.forEach(value => {
404+
tweenData.forEach(value => {
405405
Object.keys(value).forEach(name => {
406406
if (!(name in $data)) {
407407
const styleName = toCssLowerCase(isTransform(getGsapType(name)));
408-
domStyleToArray = domStyleToArray.filter(item => item[0] !== styleName);
408+
domStyleToArray = domStyleToArray.filter(item => {
409+
if (item[0].match(/transform|filter/ig) && styleName.match(/transform|filter/ig)) {
410+
return false;
411+
}
412+
return item[0] !== styleName;
413+
});
409414
}
410415
})
411416
});
@@ -431,20 +436,23 @@ p.resetDefaultStyle = function () {
431436
Object.keys(this.startDefaultData).forEach(key => {
432437
if (!(key in data)) {
433438
if (key === 'style') {
434-
const value = this.getDefaultStyle(this.target.style.cssText);
439+
const value = getDefaultStyle(this.target.style.cssText,
440+
this.startDefaultData.style,
441+
this.data);
435442
this.target.setAttribute(key, value);
436443
} else {
437444
this.target.setAttribute(key, this.startDefaultData[key]);
438445
}
439-
this.target.setAttribute(key, this.startDefaultData[key]);
440446
this.computedStyle = null;
441447
}
442448
});
443449
};
444450

445451
p.reStart = function (style) {
446452
this.start = {};
447-
this.target.style.cssText = this.getDefaultStyle(this.target.style.cssText);
453+
this.target.style.cssText = getDefaultStyle(this.target.style.cssText,
454+
this.startDefaultData.style,
455+
this.data);
448456
Object.keys(style || {}).forEach(key => {
449457
this.target.style[key] = stylesToCss(key, style[key]);
450458
});

tests/tweenOne.spec.jsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ describe('rc-tween-one', () => {
109109
x: '+=100',
110110
transformOrign: '30% 10%',
111111
delay: 100,
112+
yoyo: true,
112113
},
113114
style: { top: 0, left: '10vw', width: '5vh', height: '10%', marginLeft: '10rem' },
114115
});
@@ -123,6 +124,25 @@ describe('rc-tween-one', () => {
123124
}, 600);
124125
});
125126

127+
it('tween-one repeat -1 and yoyo', (done) => {
128+
instance = createTweenInstance({
129+
animation: {
130+
top: 100,
131+
repeat: -1,
132+
yoyo: true,
133+
},
134+
style: { top: 0},
135+
});
136+
const child = TestUtils.findRenderedDOMComponentWithTag(instance, 'div');
137+
console.log('start:', child.style.top);
138+
expect(getFloat(child.style.top)).to.be(0);
139+
ticker.timeout(() => {
140+
console.log('end:', child.style.top);
141+
expect(getFloat(child.style.top)).to.above(0);
142+
done();
143+
}, 200);
144+
});
145+
126146
it('single tween-one duration is 0', (done) => {
127147
let start;
128148
let update;

0 commit comments

Comments
 (0)