Skip to content

Commit b8de140

Browse files
committed
remove willChange and update timeline mode
1 parent 4940b77 commit b8de140

File tree

7 files changed

+22
-52
lines changed

7 files changed

+22
-52
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ React.render(<TweenOneGroup>
9595
| onChange | func | null | when the animation change called, callback({ moment, item, tween, index, mode}) |
9696
| moment | number | null | set the current frame |
9797
| attr | string | `style` | `style` or `attr`, `attr` is tag attribute. when morph SVG must be `attr`. |
98-
| willChange | boolean | true | open will-change style. |
9998
| resetStyleBool | boolean | false | update animation data, reset init style |
10099
| updateReStart | boolean | true | update animation data, re start animate |
101100
| component | string / React.Element | `div` | component tag |
@@ -182,5 +181,4 @@ object: `animation={{ path: { x: path, y: path, rotate: path } }}`, can be contr
182181
| onEnd | func | - | one animation end callback |
183182
| animatingClassName | array | `['tween-one-entering', 'tween-one-leaving']` | className to every element of animating |
184183
| resetStyleBool | boolean | true | whether to animation reset the style every time |
185-
| willChange | boolean | true | open child will-change style, transfer to child |
186184
| component | React.Element/String | div | component tag |

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

src/TimeLine.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ function defaultData(vars, now) {
3535
const timeLine = function (target, toData, props) {
3636
this.target = target;
3737
this.attr = props.attr || 'style';
38-
this.willChange = props.willChange;
3938
// 记录总时间;
4039
this.totalTime = 0;
4140
// 记录当前时间;
@@ -44,8 +43,6 @@ const timeLine = function (target, toData, props) {
4443
this.defaultData = [];
4544
// 每个的开始数据;
4645
this.start = {};
47-
// 记录动画开始;
48-
this.onStart = {};
4946
// 开始默认的数据;
5047
this.startDefaultData = {};
5148
// 动画过程
@@ -159,7 +156,7 @@ p.getAnimStartData = function (item) {
159156
this.computedStyle = this.computedStyle || this.getComputedStyle();
160157
Object.keys(item).forEach(_key => {
161158
if (_key in _plugin || (this.attr === 'attr' && (_key === 'd' || _key === 'points'))) {
162-
start[_key] = item[_key].getAnimStart(this.computedStyle, this.willChange);
159+
start[_key] = item[_key].getAnimStart(this.computedStyle);
163160
return;
164161
}
165162
if (this.attr === 'attr') {
@@ -282,34 +279,36 @@ p.render = function () {
282279
item.onComplete(e);
283280
}
284281
item.mode = 'onComplete';
285-
} else if (progressTime < this.perFrame) {
286-
ratio = item.ease(0, startData, endData, 1);
282+
} else if (progressTime >= 0 && progressTime < duration) {
283+
ratio = item.ease(progressTime, startData, endData, duration);
287284
this.setRatio(ratio, item, i);
288-
// 将第一帧作动画开始 start;
289285
if (!updateAnim) {
290-
if (item.repeat && repeatNum > 0) {
286+
const startProto = this.start[i];
287+
if (!startProto._tweenOnEnter) {
288+
item.mode = 'onStart';
289+
startProto._tweenOnEnter = true;
290+
item.onStart(e);
291+
} else if (item.repeat && repeatNum > 0 && startProto._tweenRepeatNum !== repeatNum) {
291292
item.mode = 'onRepeat';
292293
item.onRepeat({ ...e, repeatNum });
294+
startProto._tweenRepeatNum = repeatNum;
293295
} else {
294-
item.mode = 'onStart';
295-
item.onStart(e);
296+
item.mode = 'onUpdate';
297+
item.onUpdate({ ratio, ...e });
296298
}
297299
}
298-
} else if (progressTime > 0 && progressTime < duration) {
299-
item.mode = 'onUpdate';
300-
ratio = item.ease(progressTime, startData, endData, duration);
301-
this.setRatio(ratio, item, i);
302-
if (!updateAnim) {
303-
item.onUpdate({ ratio, ...e });
304-
}
305300
}
301+
306302
if (!updateAnim) {
307303
this.onChange({
308304
moment: this.progressTime,
309305
mode: item.mode,
310306
...e,
311307
});
312308
}
309+
} else if (progressTime < 0 && this.start[i]) {
310+
delete this.start[i]._tweenOnEnter;
311+
delete this.start[i]._tweenRepeatNum;
313312
}
314313
});
315314
};
@@ -321,7 +320,6 @@ p.frame = function (moment) {
321320
p.resetAnimData = function () {
322321
this.tween = {};
323322
this.start = {};
324-
this.onStart = {};
325323
};
326324

327325
p.resetDefaultStyle = function () {

src/TweenOne.jsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class TweenOne extends Component {
130130
const props = this.props;
131131
if (props.animation && Object.keys(props.animation).length) {
132132
this.timeLine = new TimeLine(this.dom, dataToArray(props.animation),
133-
{ attr: props.attr, willChange: props.willChange });
133+
{ attr: props.attr });
134134
// 预先注册 raf, 初始动画数值。
135135
this.raf();
136136
// 开始动画
@@ -205,7 +205,6 @@ class TweenOne extends Component {
205205
'moment',
206206
'resetStyleBool',
207207
'updateReStart',
208-
'willChange',
209208
].forEach(key => delete props[key]);
210209
props.style = { ...this.props.style };
211210
Object.keys(props.style).forEach(p => {
@@ -246,7 +245,6 @@ TweenOne.propTypes = {
246245
reverseDelay: PropTypes.number,
247246
moment: PropTypes.number,
248247
attr: PropTypes.string,
249-
willChange: PropTypes.bool,
250248
onChange: PropTypes.func,
251249
resetStyleBool: PropTypes.bool,
252250
updateReStart: PropTypes.bool,
@@ -257,7 +255,6 @@ TweenOne.defaultProps = {
257255
reverseDelay: 0,
258256
attr: 'style',
259257
onChange: noop,
260-
willChange: true,
261258
updateReStart: true,
262259
};
263260
export default TweenOne;

src/TweenOneGroup.jsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ class TweenOneGroup extends Component {
121121
onChange = this.onChange.bind(this, animation, child.key, type);
122122
const animate = transformArguments(animation, child.key, i);
123123
const props = {
124-
willChange: this.props.willChange,
125124
key: child.key,
126125
animation: animate,
127126
onChange,
@@ -168,7 +167,6 @@ class TweenOneGroup extends Component {
168167
'animatingClassName',
169168
'onEnd',
170169
'resetStyleBool',
171-
'willChange',
172170
].forEach(key => delete componentProps[key]);
173171
return createElement(this.props.component, componentProps, childrenToRender);
174172
}
@@ -183,7 +181,6 @@ TweenOneGroup.propTypes = {
183181
leave: PropTypes.any,
184182
animatingClassName: PropTypes.array,
185183
onEnd: PropTypes.func,
186-
willChange: PropTypes.bool,
187184
resetStyleBool: PropTypes.bool,
188185
};
189186

@@ -194,7 +191,6 @@ TweenOneGroup.defaultProps = {
194191
enter: { x: 50, opacity: 0, type: 'from' },
195192
leave: { x: -50, opacity: 0 },
196193
onEnd: noop,
197-
willChange: true,
198194
resetStyleBool: true,
199195
};
200196
TweenOneGroup.isTweenOneGroup = true;

src/plugin/StylePlugin.jsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,11 @@ p.convertToMarksArray = function (unit, key, data, i) {
9696
return startConvertToEndUnit(this.target, key, data,
9797
startUnit, endUnit, null, key === 'transformOrigin' && !i);
9898
};
99-
p.getAnimStart = function (computedStyle, willChangeBool) {
99+
p.getAnimStart = function (computedStyle) {
100100
const style = {};
101101
this.supports3D = checkStyleName('perspective');
102-
let willChangeArray;
103-
if (willChangeBool) {
104-
this.willChange = computedStyle.willChange === 'auto' || !computedStyle.willChange ||
105-
computedStyle.willChange === 'none' ? '' : computedStyle.willChange;
106-
willChangeArray = this.willChange.split(',').filter(k => k);
107-
}
108102
Object.keys(this.propsData.data).forEach(key => {
109103
const cssName = isConvert(key);
110-
if (willChangeBool) {
111-
const willStyle = key in _plugin ? this.propsData.data[key].useStyle || cssName : cssName;
112-
if (willChangeArray.indexOf(willStyle) === -1 &&
113-
(willStyle in computedStyle || key in _plugin)) {
114-
willChangeArray.push(willStyle.replace(/([A-Z])/g, '-$1').toLocaleLowerCase());
115-
}
116-
this.willChange = willChangeArray.join(',');
117-
}
118104
let startData = computedStyle[cssName];
119105
const fixed = computedStyle.position === 'fixed';
120106
if (!startData || startData === 'none' || startData === 'auto') {
@@ -227,13 +213,6 @@ p.setRatio = function (ratio, tween) {
227213
tween.style.transform = tween.style.transform || { ...this.start.transform };
228214
}
229215
const style = this.target.style;
230-
if (this.willChange) {
231-
if (ratio === (this.type === 'from' ? 0 : 1)) {
232-
style.willChange = null;
233-
} else {
234-
style.willChange = this.willChange;
235-
}
236-
}
237216
Object.keys(this.propsData.data).forEach(key => {
238217
const _isTransform = isTransform(key) === 'transform';
239218
let startVars = _isTransform ? this.start.transform[key] : this.start[key];

src/plugin/SvgDrawPlugin.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ SvgDrawPlugin.prototype = {
7878
case 'ellipse':
7979
this.length = this.getEllipseLength();
8080
break;
81-
default:
81+
case 'path':
8282
this.length = this.target.getTotalLength();
8383
break;
84+
default:
85+
throw new Error('The label is not a label in the SVG.');
8486
}
8587
this.length = parseFloat(this.length.toFixed(3));
8688
this.start.strokeDasharray = computedStyle.strokeDasharray === 'none'

0 commit comments

Comments
 (0)