question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No layout available for index: 0

See original GitHub issue

I’m seeing errors coming through in Bugsnag that seem to be from my implementation of RecyclerListView. The error says No layout available for index: 0. I can’t seem to reproduce it myself but I know that it’s causing some of my users pain. As far as I know I’ve set up everything correctly, but maybe I’m missing something. Here’s the applicable code from my component.

// different layout types
enum layoutStyle {
  GRID = 'Grid',
  LIST = 'List',
}
  // starting up the component
  constructor(props: Props) {
    super(props);

    this.dataProvider = new DataProvider(
      (p1: Adult | Student, p2: Adult | Student) => {
        return (
          p1.uniqueidentifier !== p2.uniqueidentifier ||
          p1.firstName !== p2.firstName ||
          p1.lastName !== p2.lastName
        );
      }
    );

    this.state = {
      layout: layoutStyle.GRID,
    };

    const pageWidth = Dimensions.get('window').width;
    const columnCount = Math.floor(pageWidth / Person.minTileWidth);
    const gridWidth = Math.floor(pageWidth / columnCount);

    this.layoutProvider = new LayoutProvider(
      () => this.state.layout,
      (
        type: layoutStyle,
        dim: {
          width: number;
          height: number;
        }
      ) => {
        switch (type) {
          case layoutStyle.GRID:
            dim.width = gridWidth;
            dim.height = 96;
            break;
          case layoutStyle.LIST:
            dim.width = Dimensions.get('window').width;
            dim.height = 70;
            break;
          default:
            dim.width = 0;
            dim.height = 0;
        }
      }
    );
  }
        // in the render function
        <RecyclerListView
          layoutProvider={this.layoutProvider}
          dataProvider={this.dataProvider.cloneWithRows(people)}
          rowRenderer={this.rowRenderer}
          renderAheadOffset={200}
          extendedState={this.state}
          ref={(ref: RecyclerListView) => {
            if (ref) {
              this.listViewRef = ref;
            }
          }}
        />

From the error message it sounds like my LayoutProvider instance may not be configured correctly, but I went back through and reviewed the demo code in this repo and it looks like it should work fine to me.

Any help on this would be appreciated. Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

4reactions
devilyardcommented, Apr 19, 2019

I’m facing the same problem now, in my case, the error happens when loaded with some rows first, then reload without any data for the list, then the error will be shown.

1reaction
jasonmerinocommented, Sep 6, 2019

Today I finally got around to dealing with this error. My solution is not ideal, but it works.

Right before rendering the RecyclerListView component I check to make sure that the items I’m trying to render are greater than 0. If the length of my array of items is 0 I just render an empty View component instead of the RecyclerListView. Not ideal, but it seems to do the trick in my situation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Filter data for RecyclerListView - reactjs - Stack Overflow
I'm trying to implement basic list with a filter using RecyclerListView. But as soon as type some text and the scroll is not...
Read more >
ViewGroup - Android Developers
android:clipToPadding, Defines whether the ViewGroup will clip its children and resize (but not clip) any EdgeEffect to its padding, if padding is not...
Read more >
GridPane (JavaFX 8) - Oracle Help Center
If not set, row sizing and layout behavior is computed based on content. Index in the ObservableList denotes the row number, so the...
Read more >
Documentation: 15: 73.6. Database Page Layout - PostgreSQL
Every table and index is stored as an array of pages of a fixed size (usually 8 ... 7.3 and 7.4 used version...
Read more >
Stacking without the z-index property - CSS - MDN Web Docs
When the z-index property is not specified on any element, elements are stacked in the following order (from bottom to top):
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found