Skip to content

Commit 020a22f

Browse files
committed
1 parent eaadddb commit 020a22f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
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.7.2",
3+
"version": "2.7.3",
44
"description": "tween-one anim component for react",
55
"keywords": [
66
"react",

src/TweenOne.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class TweenOne extends Component {
125125
this.reverse = props.reverse;
126126
this.updateAnim = false;
127127
this.repeatNum = 0;
128+
// 定义 ref 给外部使用;
129+
this.currentRef = null;
128130
this.forced = {};
129131
this.setForcedJudg(props);
130132
this.state = {
@@ -334,6 +336,9 @@ class TweenOne extends Component {
334336
});
335337
}
336338
});
339+
const refFunc = (c) => {
340+
this.currentRef = c;
341+
}
337342
// component 为空时调用子级的。。
338343
const { className, children } = props;
339344
if (!component && typeof children !== 'string') {
@@ -345,9 +350,10 @@ class TweenOne extends Component {
345350
// 合并 style 与 className。
346351
const newStyle = { ...childStyle, ...props.style };
347352
const newClassName = className ? `${className} ${childClass}` : childClass;
348-
return React.cloneElement(children, { style: newStyle, className: newClassName });
353+
return React.cloneElement(children, { style: newStyle, ref: refFunc, className: newClassName });
349354
}
350355
return React.createElement(component, {
356+
ref: refFunc,
351357
...props,
352358
...componentProps,
353359
});

0 commit comments

Comments
 (0)