Skip to content
This repository was archived by the owner on Apr 11, 2018. It is now read-only.

Commit 96bfda3

Browse files
committed
feat(expand-animation): add life-cycle hooks for the entering component
1 parent fdc33f3 commit 96bfda3

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/Expand.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export default class Expand extends React.Component {
1717
]),
1818
className: React.PropTypes.string,
1919
collapseDuration: React.PropTypes.number,
20+
componentDidExpand: React.PropTypes.func,
21+
componentWillExpand: React.PropTypes.func,
2022
expandDuration: React.PropTypes.number,
2123
style: React.PropTypes.object
2224
}

src/ExpandChild.jsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export default class ExpandChild extends React.Component {
1212
React.PropTypes.node
1313
]),
1414
collapseDuration: React.PropTypes.number,
15+
componentDidExpand: React.PropTypes.func,
16+
componentWillExpand: React.PropTypes.func,
1517
expandDuration: React.PropTypes.number
1618
}
1719

@@ -76,16 +78,33 @@ export default class ExpandChild extends React.Component {
7678
}
7779

7880
componentWillEnter(done) {
79-
const { animateOnExpand, expandDuration } = this.props;
81+
const {
82+
animateOnExpand,
83+
componentDidExpand,
84+
componentWillExpand,
85+
expandDuration
86+
} = this.props;
87+
8088
const maxHeight = this.componentHeight();
8189
const calc = (progress) => maxHeight * progress;
8290

8391
this.style = { height: 0 };
8492

93+
const callback = () => {
94+
if (componentDidExpand) {
95+
componentDidExpand();
96+
}
97+
done();
98+
};
99+
100+
if (componentWillExpand) {
101+
componentWillExpand();
102+
}
103+
85104
if (animateOnExpand) {
86-
this.animate(calc, expandDuration, done);
105+
this.animate(calc, expandDuration, callback);
87106
} else {
88-
done();
107+
callback();
89108
}
90109
}
91110

0 commit comments

Comments
 (0)