neptunian / react-photo-gallery

React Photo Gallery
http://neptunian.github.io/react-photo-gallery/
Other
1.97k stars 310 forks source link

Add ability to pass containerWidth with props #186

Open PaperPlane01 opened 4 years ago

PaperPlane01 commented 4 years ago

Hi! First of all, thanks for your library, it's really awesome :) I'm using your library in a chat app to display images attached to a message. Inside the app, it's possible to switch between normal scroll and virtual scroll for chat messages. When scroll is normal, your library works great. However, when I switch to usage of virtual scroll, images which are in the end of visible area, are starting to resize rapidly for some reason which makes scroll very jank. It seems like ResizeObserver, which is used to calculate the width of gallery, is triggered too many times for some reason. However, I've find out that if I explicitly pass containerWidth with props (which I can easily calculate), handle resize on my own and make Gallery component rely on that instead of ResizeObserver, the images are now rendered as normal. So I would really appreciate if this functionality was added in this library Currently I'm using my fork (https://github.com/PaperPlane01/react-photo-gallery) in a project which shows how this might be implemented (https://github.com/PaperPlane01/react-photo-gallery/blob/master/src/Gallery.js) Thanks!