You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Items placed using pinterest layout are properly arranged. No overlapping, gutters correctly place and distributed
Items got an image and text
simple layout would just overlap / smash every item
I don't particularly need à la pinterest layout but every column starting a a common height
I tried to pass a custom layout overwriting the pinterest layout code.
I've got this:
import{chunk}from"lodash";exportdefaultfunction(items,props){const{ columns, columnWidth, gutterWidth, gutterHeight }=props;constcolumnHeights=[];for(leti=0;i<columns;i++){columnHeights.push(0);}constpositions=items.map(itemProps=>{constcolumn=columnHeights.indexOf(Math.min.apply(null,columnHeights));constheight=itemProps.itemHeight||(itemProps.itemRect&&itemProps.itemRect.height);if(!(height&&typeofheight==="number")){thrownewError('Each child must have an "itemHeight" prop or an "itemRect.height" prop.');}constx=column*columnWidth+column*gutterWidth;consty=columnHeights[column];columnHeights[column]+=Math.round(height)+gutterHeight;return[x,y];});constallHeights=items.map(itemProps=>itemProps.itemHeight||(itemProps.itemRect&&itemProps.itemRect.height));constchunkHeights=chunk(allHeights,columns);constgridWidth=columns*columnWidth+(columns-1)*gutterWidth;constgridHeight=Math.max.apply(null,columnHeights);constrows=chunk(positions,columns);letpreviewRowYStart=0;letpreviewRowYEnd=0;constorderedPositions=rows.map((row: any,rowIndex)=>{constcolumnsYPositions=row.map(([x,y])=>y);constmax=Math.max(...columnsYPositions);letyPosition=max;if(rowIndex!==0){constoverlap=previewRowYEnd>=max;if(overlap)yPosition=(max+(previewRowYEnd-max))*1.05;}previewRowYStart=rowIndex===0 ? 0 : max;previewRowYEnd=max+Math.max(...chunkHeights[rowIndex]asnumber[]);returnrow.map(([x])=>[x,yPosition]);});return{positions: orderedPositions.flat(1), gridWidth, gridHeight };}
Where basically I'm trying to order the item Y position into chunks according to their row, take the highest and set a common Y for all of them. Also I'd take previous row height and detect the chance of an overlap, adding some extra distance if overlapping.
This seems to work except that in some cases, the distance between rows is huge. I've tried to adjust the yPosition calculation when there's an overlap and also reduced the gutter but I can't get a consistent and logic result.
Any suggestions or directions would be appreciated
The text was updated successfully, but these errors were encountered:
I've found myself with the following situation:
I tried to pass a custom layout overwriting the pinterest layout code.
I've got this:
Where basically I'm trying to order the item Y position into chunks according to their row, take the highest and set a common Y for all of them. Also I'd take previous row height and detect the chance of an overlap, adding some extra distance if overlapping.
This seems to work except that in some cases, the distance between rows is huge. I've tried to adjust the
yPosition
calculation when there's an overlap and also reduced the gutter but I can't get a consistent and logic result.Any suggestions or directions would be appreciated
The text was updated successfully, but these errors were encountered: