-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
re-animation on re-render #31
Comments
Hi, @tcurdt it is very hard to tell what is going on with your code without being able to run it =). The easiest I can advise blindly - create a small component with The rule is simple - when immediate children are re-rendered - Collapse recalculates height and is re-rendered too. So if children are changed by anything from outside (not Collapse), this will happen. Also put something like If you can fork http://codepen.io/nkbt/pen/MarzEg and create your own reproducable example - that would help a lot. |
I'm seeing this behavior as well. |
I know - it's hard to help when you can't reproduce it. Things is though: The children are not changing at all. So if the re-calc happens - it will give the very same result. Yet the animation is running for a very brief moment. |
@tcurdt yup I am seeing the same thing. The children are not changing yet animation runs for a split second... |
I know it's a cop out, and it's better to change the element instead, but passing the <Collapse isOpened={this.state.opened}>
<ChildComponent
style={{
display: this.state.opened ? 'inherit' : 'none'
}}
/>
</Collapse> If I get time, I'll try to reproduce it since I also have a redux store changing in my app. |
@jermspeaks |
@nkbt Yeah, I noticed that. Like I said, I'll try to reproduce the issue. This temporary workaround is not hitting the bigger issue of mounting child components. If I figure it out, I'll send a PR. :) |
Neat, thanks. Let me know if you need any help. You can find me in http://www.reactiflux.com or https://gitter.im/nkbt if you need real-time comunication |
Hi, I have this issue when nesting Collapse (version 2.3.1) and just want to give some more info, maybe it helps. <Collapse isOpened={selected} keepCollapsedContent={true}>
<Collapsible1/>
<Collapsible2/>
</Collapse> where the inner Collapsible are classes (typescript) like this: class Collapsible1 extends React.Component<...> {
constructor(props){
this.state = {collapsed: true};
}
render (){
return (
<div>
<div className={'head'} onClick={() => this.setState({collapsed: !this.state.collapsed})}>Open</div>
<Collapse isOpened={this.state.collapsed}>Some content</Collapse>
</div>
)
}
} What I found from debugging is that when uncollapsing the inner Collapsible by clicking on the head, the height of the whole element changes dynamically, but I think the outer Collapse.height attribute is not updated (onHeightReady is not called). After that, there is some other action in my app that triggers the redux reload which triggers a re-rendering, which then recalculates height on the outer Collapse (onHeightReady) which then triggers the animation, but only once on the first redux reload. After some trial and error on the src code I found the following patch fixing my problem (at least for the moment): function onHeightReady(height) {
const {isOpened, keepCollapsedContent, onHeightReady} = this.props;
if (this.renderStatic && isOpened) {
this.height = Collapse.prototype.stringHeight(height);
}
if (keepCollapsedContent) {
// ----------- introduced this line -------------
this.height = Collapse.prototype.stringHeight(height);
// -----------------------------------------
this.setState({height});
} else {
this.setState({height: isOpened || !this.renderStatic ? height : 0});
}
const reportHeight = isOpened ? height : 0;
if (this.state.height !== reportHeight) {
onHeightReady(reportHeight);
}
}; I found the additional line ensures skipAnimation = true when Collapse.getMotionHeight() is called. I haven't been able to understand the whole lifecycle of Collapse, but maybe this gives some hint. |
I am doing some major rewrite in #72, which should address most issues (except the realtime tracking of nested height, which is "by design" decision, though I might find the way to fix it too). |
Confirmed, that it is fixed by #72 |
Just published |
Now on a few occasions a react re-render causes the animation to re-run (the end bit of it at least).
Unfortunately I cannot reliably reproduce it yet.
It's a bit weird. I have the redux store changing (of course that causes a re-render) but nothing related to react-collapse changes.
The text was updated successfully, but these errors were encountered: