recyclerlistview icon indicating copy to clipboard operation
recyclerlistview copied to clipboard

Allow width and height data type for LayoutProvider return type

Open oste opened this issue 3 years ago • 1 comments
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);

oste avatar Feb 25 '22 04:02 oste

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?

oste avatar Feb 26 '22 14:02 oste