Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jljsj33 committed Jul 20, 2020
1 parent eaadddb commit 020a22f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-tween-one",
"version": "2.7.2",
"version": "2.7.3",
"description": "tween-one anim component for react",
"keywords": [
"react",
Expand Down
8 changes: 7 additions & 1 deletion src/TweenOne.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class TweenOne extends Component {
this.reverse = props.reverse;
this.updateAnim = false;
this.repeatNum = 0;
// 定义 ref 给外部使用;
this.currentRef = null;
this.forced = {};
this.setForcedJudg(props);
this.state = {
Expand Down Expand Up @@ -334,6 +336,9 @@ class TweenOne extends Component {
});
}
});
const refFunc = (c) => {
this.currentRef = c;
}
// component 为空时调用子级的。。
const { className, children } = props;
if (!component && typeof children !== 'string') {
Expand All @@ -345,9 +350,10 @@ class TweenOne extends Component {
// 合并 style 与 className。
const newStyle = { ...childStyle, ...props.style };
const newClassName = className ? `${className} ${childClass}` : childClass;
return React.cloneElement(children, { style: newStyle, className: newClassName });
return React.cloneElement(children, { style: newStyle, ref: refFunc, className: newClassName });
}
return React.createElement(component, {
ref: refFunc,
...props,
...componentProps,
});
Expand Down

1 comment on commit 020a22f

@jljsj33
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#86

Please sign in to comment.