-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
WindowScroll + Masonry + AutoSizer + CellMeasurer cells are not resized #979
Comments
FWIW, this has nothing to do with
Check out the source code for the |
Yep, I saw that example and I basically did the same thing (but shorter for sake of demo) by making |
There is an example of this being done in the code I linked you to...
…On Sun, Jan 21, 2018 at 1:13 PM Kirill Konshin ***@***.***> wrote:
Yep, I saw that example and I basically did the same thing (but shorter
for sake of demo) by making columnWidth accessible via newWidth variable.
But this is nasty :) I'd say that if we change columnWidth, then it makes
sense to reset the CellMeasurerCache with new value.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#979 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABznb-mcjdLCj3p0-LJuZzqtFzSKQ45ks5tM6hdgaJpZM4Rl9WG>
.
|
Do you mean this: In your demo you use |
Your reply is antagonistic. If you think the component is useless, don't use it. I don't want to debate the usefulness of code I spent time writing and open-sourcing via a GitHub issue. The documentation clearly states that sync measurements are a constraint of the Beyond that, I've provided example code of how to accomplish width changes. There's no reason to re-use the cache vs creating a new one. Either way, all height measurements are invalidated. |
Not trying to underestimate your efforts, this is a great lib! I was saying that looks like it becomes pointless to call So the current recommended approach is to ignore measured width and replace it with calculated width from state/var? I am facing another problem, this probably requires another issue, but let me ask here first. I have added dynamic loading of data to my example https://codesandbox.io/s/73921rmy0x I export a class Any window resize fixes the layout. I found a solution to call What would be the best way to fix this? |
I was saying that looks like it becomes pointless to call measure function for Masonry because it does nothing.
Correct. The CellMeasurerCache is used for both Masonry as well as List/Grid/Table. Masonry is not built to support async measurements. The other three are. That's why the docs list the Masonry constraint.
Your follow up question is better suited for Stack Overflow or Slack than GitHub. I suggest asking there!
|
It looks more like a bug to me, frankly speaking... if list with images is provided from beginning as part of state, then layout works well. But if it is "loaded" via timeout then I see layout glitch (e.g. masonry is drawn twice, without data and with data). Immediately after window resize it's positioned correctly. I have double checked the demo, looks like some older version was served, pls take a look https://codesandbox.io/s/73921rmy0x?module=%2Fpages%2Findex.js |
That's because you're using the component incorrectly. I have reference the
|
I'm sorry, I don't get it. How is it different from If cell measurement is synchronous, then fist case with static data should fail too, images are loaded asynchronously, as a next step after rendering. But it works somehow. I checked the masonry demo: https://bvaughn.github.io/react-virtualized/#/components/Masonry this is an example of static data. Do you want to say, that it's impossible to add more images asynchronously (say, load next page)? |
I have found the reason. When images are cached first measurement is successful. With clean cache first render fails the same way as async one. Documentation should actually in addition to above-mentioned phrase refer here #723 (I came to same approach — calling debounced This approach badly affects the performance, as calculation happens every time when user scrolls (some new images are constantly loaded and unloaded at the top/bottom of viewport). I hope some day this wide-spread use case will receive some official support... |
I'm going to be honest with you and admit that this discussion has been frustrating for me. I feel that you are simultaneously complaining about missing functionality that the documentation clearly states is not supported while also ignoring my responses pointing this out. I'm stating this clearly so that you'll know where I'm coming from, in case there has been a misunderstanding. Plain text can be hard sometimes. I'm going to make one final attempt to answer your question, and after that I'm not going to continue this discussion because I don't think it's productive.
You are welcome to look through the source code to understand this. If you don't want to do that though, you'll just have to accept my word (and the documentation) that this functionality isn't meant to work within the
The data is not "static". It's randomized. But it's measurable synchronously (on-mount). If you want to load images, using the
I do not plan to add this to the documentation because it's not going to perform well and I don't have the time or energy to add support for this to the component.
This is specifically why the documentation states that it's not a supported use-case. It's also something I've said, in different words, a couple of times in this thread already.
As with any open source component, you are free to implement this functionality yourself if your application requires it. If you're feeling generous, you can submit it as a PR to this library. Or not. Your call. |
Will you accept a PR with broader explanation (based on the above-mentioned facts) right in |
The CodeSandbox in question is buggy. (Resize the width of the page and the layout breaks for pre-measured cells). If this issue is fixed, I will review and consider a PR like you describe. (I won't promise to accept it until I've reviewed it.) |
You mean when page is enlarged then growing images does not expand cells and get cut even worse than before? |
The only solution for this particular issue, as I see it, is to reset the cache |
Still working on a better implementation, can you please suggest the best way to clear the cache and force re-measure of all visible+previous cells? Or for all if it's impossible to determine which are visible? Simple Scrolling can be solved via I already added a simple cache to prevent re-positions when user scroll back and forth causing same images to call |
Finally had time for this, and managed to make this work. I've found in the masonry example the reset method, which calls cache.cleanAll();
cellPositioner.reset(...things);
masonryRef.clearCellPositions(); // instead of recomputeCellPositions That's exactly what I was looking for. https://codesandbox.io/s/6x6qkoprk sandbox updated, bug is gone. I presume this does not perform well especially if scrolled deep. |
In order to support both resize and unknown image sizes I have implemented the
I have figured, that You can swap to previous mode by changing rendered page in I'm going to release it in NPM, can I send a pull request with updated docs, demo and mention of the package? |
@bvaughn any response? |
@bvaughn I have found the working solution, and I am willing to make a PR but I don't want to waste my efforts so please take a look at it and if it's all good I will make a PR. |
@kirill-konshin thanks to your work, I could figure out why my masonry layout was not rendering properly when rendered via toggling a state variable: Your code had a little typo, but it was good enough to point me into the right direction. For future explorer (including me) - to reset the Masonry layout on subsequent renders, stick this in your
|
I have made a small setup to display a bug when using WindowScroll + Masonry + AutoSizer + CellMeasurer.
The expectation is that
cellRenderer
will receive properstyle
with properwidth
but in fact it always getsdefaultWidth
:https://codesandbox.io/s/73921rmy0x
I have fixed it with the line
//FIXME NASTY HACK
but it think it should be done differently.The text was updated successfully, but these errors were encountered: