I am trying to render the responsive image grid, which might have images of different sizes. It sounds like the Masonry component is good fit for this case, but not sure that I am able to use this example in my application? It looks fully coupled to the place where it lives, I tried to take relevant parts, but I wasn't able to get working.
Also, I have tried to generate relevant code with wizard, and got this sample:
<AutoSizer>
{({ height, width }) => (
<CellMeasurer
cellRenderer={yourCellRenderer}
columnCount={numColumns}
rowCount={numRows}
width={width}
>
{({ getRowHeight }) => (
<Grid
cellRenderer={({ columnIndex, key, rowIndex, style }) => <div key={key} style={style}>...</div>}
columnCount={numColumns}
columnWidth={({ index }) => 100}
height={height}
rowCount={numRows}
rowHeight={getRowHeight}
width={width}
/>
)}
</CellMeasurer>
)}
</AutoSizer>
But what should I put instead of yourCellRenderer
, getRowHeight
?
Based on some samples in the internet I build following piece of code:
<div className="media-viewer" style={{height: "100vh"}}>
<AutoSizer>
{({height, width}) => (
<Grid
cellRenderer={({columnIndex, key, rowIndex, style}) => {
if (!result[rowIndex][columnIndex]) return <div key={key} style={style}></div>;
return (
<div key={key} style={style}>
<MediaItem key={result[rowIndex][columnIndex].id} app={app}
item={result[rowIndex][columnIndex]}/>
</div>
);
}}
columnCount={5}
columnWidth={250}
height={height}
rowCount={result.length}
rowHeight={250}
width={width}
/>
)}
</AutoSizer>
</div>
And the result it brings to the screen:
If someone able to provide me with robust example of responsive grid based on react-virtualize
, or point where I can improve my current code, I would appreciate that.
Best regards.