Skip to content
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

After changing the content's size dynamically, it needs a resize event to adjust the scrollbar #21

Open
ziadloo opened this issue May 20, 2016 · 4 comments
Labels

Comments

@ziadloo
Copy link

ziadloo commented May 20, 2016

I have a div which I add to its children dynamically and as the result its height changes. Once the content's height is changed, the vertical scrollbar will be able to move too far to the bottom, so much that the bar will be cut off by the frame as if it has gone underneath it. But if I resize the window, the recalculation done makes everything alright again.

Is there some way I can fix this problem from my end?

@noeldelgado
Copy link
Owner

Hi, try calling the update method on the scrollbar instance reference after you have added any children dynamically.

I think you can accomplish this by adding a ref to the gemini component, such as:

// your-component.js

<GeminiScrollbar ref='gemini'>
...
</GeminiScrollbar>

then you can do something like this.refs.gemini.scrollbar.update();.

Let me know if that works for you.

Btw, how are you adding the children dynamically? shouldn't the componentDidUpdate method being run at that point? The scrollbar component should run the update itself when that method gets fired.

// gemini-scrollbar/index.js

componentDidUpdate() {
  this.scrollbar.update();
},

@ziadloo
Copy link
Author

ziadloo commented May 20, 2016

You are right, your code works fine if there's no animation involved. But since I add the new components with animation over a period of time and the animation affects the size of the content, that makes the problem. I mean if I remove the <ReactCSSTransitionGroup> element, the height is calculated perfectly.

Do you have any generic solution for content with animation? I mean I can come up with one for myself but I wonder if you've already solved it in a decent way!

@noeldelgado
Copy link
Owner

Sorry, I haven't worked with animation before (using React). I look forward to seeing what you come up with!

@ziadloo
Copy link
Author

ziadloo commented May 20, 2016

The right approach would be using ReactTransitionGroup class and implement your own version of ReactCSSTransitionGroup so you can recalculate whatever you need once the animation is done. For the time being I took the dirty approach and just added a timer to call the update method after the animation is over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants