Thanks to this approach, server-side rendered markup looks pixel-perfect on the client even before hydration (or even when JavaScript is completely disabled in the browser). Unlike its predecessor, React Photo Album avoids setting the exact dimensions of images in pixels. React Photo Album extensively uses CSS flexbox and CSS calc function to calculate the dimensions of images on the client. ![]() In the case of SSR, React Photo Album includes sizes and srcset image attributes in the server-rendered markup, allowing browsers to pick images of the most appropriate resolution depending on their viewport size. React Photo Album automatically generates sizes and srcset image attributes. This layout does not completely fill the rectangular container space, but the columns end up being as close in height to each other as possible. Masonry layout arranges photos into columns of equal width by placing each photo into the shortest column. This layout uses an algorithm very similar to the one described above, but instead of Dijkstra's algorithm, it uses a dynamic programming algorithm to find the shortest path of length N in a directed weighted graph. Columns LayoutĬolumns layout fills the rectangular container space by arranging photos into a predefined number of columns, determined by the columns parameter. The graph is being built as the shortest path is being calculated to improve algorithm's performance, so the entire adjacency list is not calculated ahead of time. It solves the issue of panoramas shrinking rows or having stragglers or stretched images in the last row, instead creating a justified grid. This algorithm produces rows that are similar in height and photos that are not being stretched or shrunken abnormally (as is what happens in a naive implementation). The cost of each edge is calculated as the squared deviation from the targetRowHeight. To calculate the single best layout, it uses Dijkstra's algorithm to find the shortest past in a graph where each photo to break on represents a node, and each row represents an edge. This layout uses an algorithm adapted from the Knuth and Plass line breaking algorithm. ![]() Rows layout fills the rectangular container space by arranging photos into rows that are similar in size, with the height of each row being as close to the targetRowHeight as possible. To install React Photo Album on a static website via CDN, follow one of the CDN examples. Minimal Setup Example import PhotoAlbum from "react-photo-album" Installation npm install react-photo-album Performance: it was built with performance in mind in order to support large photo albums and silky smooth layoutĪll examples are available on CodeSandbox.TypeScript: type definitions come built-in in the package.Feature packed: supports 3 layout options (rows, columns and masonry), responsive images, custom data attributesĪnd is fully configurable and customizable.Responsive images: responsive images with automatic resolution switching are supported out of the box. ![]() ![]() SSR friendly: produces server-side rendered markup that looks pixel perfect on the client even before hydration.Built for React: works with React 17 and 16.14.0+.eventsĪll documented events are exported as props (function names). This code is generated from the original library.
0 Comments
Leave a Reply. |