How to wait until RecyclerListView was measured?

505 views Asked by At

I run in the following error with RecylerListView.

scrollTo was called before RecyclerListView was measured, please wait for the mount to finish

How can I make sure that the scrollTo function is not called until RecylerListView has finished measuring?

The following approach is not working...

if (recyclerRef?.current ) {
        recyclerRef.current?.scrollToIndex(index, true);
      }
1

There are 1 answers

0
Animalz On

I found some sort of a workaround for my specific case, you just delay the function for 10ms:

onContentSizeChange={async () => 
{
  await this.SomeMilliSecondsTimeout();
  this.flatList.scrollToEnd({animated: false});
}}

..............

async SomeMilliSecondsTimeout  () {
  await new Promise((res, rej) => 
   {
     setTimeout(res, 10);
   });
}

In my example i have got 60 items in my list. You can play around with the timer. This all happens inside a React.Component class, so dont wonder about my function notation. After doing this, the warning disappears.