recyclerlistview
recyclerlistview copied to clipboard
Allow width and height data type for LayoutProvider return type
trafficstars
I ended up with a layout provider like this:
return new LayoutProvider(
(index) => {
const data = postsDataProvider.getDataForIndex(index);
return `${data.width}x${data.height}`;
},
(type, dim) => {
const [width, height] = String(type).split('x');
dim.width = parseInt(width);
dim.height = parseInt(height);
}
);
The LayoutProvider type looks like below so it is required to return a string or number instead of maybe a more convenient type like {width: number, height: number }.
constructor(getLayoutTypeForIndex: (index: number) => string | number, setLayoutForType: (type: string | number, dim: Dimension, index: number) => void);
It seems like layout provider could just be a function that receives an index and is expected to return the dimensions like (index: number) => Dimensions. Maybe I am missing something and this is an anti pattern somehow?