Skip to content

Commit eaadddb

Browse files
committed
re findDOMNode
1 parent f343dcb commit eaadddb

File tree

2 files changed

+6
-16
lines changed

2 files changed

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

src/TweenOne.jsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,16 @@ class TweenOne extends Component {
133133
}
134134

135135
componentDidMount() {
136-
this.setDom()
136+
this.dom = ReactDom.findDOMNode(this);
137137
if (this.dom && this.dom.nodeName !== '#text') {
138138
this.start();
139139
}
140140
}
141141

142142
componentDidUpdate() {
143-
this.setDom();
143+
if (!this.dom) {
144+
this.dom = ReactDom.findDOMNode(this);
145+
}
144146
// 样式更新了后再执行动画;
145147
if (this.updateAnim && this.dom && this.dom.nodeName !== '#text') {
146148
if (this.tween) {
@@ -190,10 +192,6 @@ class TweenOne extends Component {
190192
this.startTime = ticker.time;
191193
};
192194

193-
setDom = () => {
194-
this.dom = this.dom || ReactDom.findDOMNode(this);
195-
}
196-
197195
restart = () => {
198196
if (!this.tween) {
199197
return;
@@ -338,9 +336,6 @@ class TweenOne extends Component {
338336
});
339337
// component 为空时调用子级的。。
340338
const { className, children } = props;
341-
const ref = c => {
342-
this.dom = c;
343-
};
344339
if (!component && typeof children !== 'string') {
345340
if (!children) {
346341
return children;
@@ -350,14 +345,9 @@ class TweenOne extends Component {
350345
// 合并 style 与 className。
351346
const newStyle = { ...childStyle, ...props.style };
352347
const newClassName = className ? `${className} ${childClass}` : childClass;
353-
return React.cloneElement(children, {
354-
style: newStyle,
355-
ref,
356-
className: newClassName,
357-
});
348+
return React.cloneElement(children, { style: newStyle, className: newClassName });
358349
}
359350
return React.createElement(component, {
360-
ref: typeof component === 'string' ? ref : undefined,
361351
...props,
362352
...componentProps,
363353
});

0 commit comments

Comments
 (0)