Skip to content

overrideItemLayout is not adjusting item span across columns #741

Open
@mmosayed

Description

@mmosayed

Current behavior

Hey I am trying to increase the amount a certain item is spanning across the columns. Here is the example of my code:

export const ViewTypes = {
  HALF_WIDTH: 0,
  FULL_WIDTH: 1,
};

const ListContainer = (props) => {
  const [ listData, setListData ] = useState([]);

  useEffect(() => {
    setListData(ListManager.get());
  }, []);

  const _renderItem = ({ item, index }) => {    
    const height = ITEM_HEIGHT;

    switch (item.type) {
      case ViewTypes.HALF_WIDTH:
        return (
          <HalfWidthView 
            height={height}
          />
        );
      case ViewTypes.FULL_WIDTH:
        return (
          <FullWidthView 
            height={height}
          />
        );
      default:
        return (
          <HalfWidthView
            height={height}
          />
        );
    }
  }

  _getItemType = (item) => {
    return item.type;
  }

  _overrideItemLayout = (layout, item, index, maxColumns) => {
    layout.size = ITEM_HEIGHT;
    layout.span = index === 0 ? 2 : 1;
  }

  return (
    <>
      <MasonryFlashList
        data={listData}
        renderItem={_renderItem}
        estimatedItemSize={ITEM_HEIGHT}
        numColumns={2}
        optimizeItemArrangement={true}
        overrideItemLayout={_overrideItemLayout}
      />
    </>
  );
};

export default  ListContainer;

Here is an example of the output:

Simulator Screen Shot - iPhone 14 - 2023-01-23 at 14 21 43

Expected behavior

I am expecting the blue box to take up 2 columns span. So the top row would be full width of the screen and allow the blue box to take up that space. The rest of the "half width" items will naturally wrap to the next row.

To Reproduce

It seems doing the following is not working:

 _overrideItemLayout = (layout, item, index, maxColumns) => {
    layout.size = ITEM_HEIGHT;
    layout.span = index === 0 ? 2 : 1;
 }

Platform:

  • [ X] iOS
  • [ X] Android

Environment

"@shopify/flash-list": "^1.4.0",

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions