Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ranveerching opened this issue Oct 21, 2022 · 2 comments

Comments

@ranveerching
Copy link

I am getting "scrollTo was called before RecyclerListView was measured, please wait for the mount to finish" warning every single time on load.

Is there any way to wait for recyclerview load or is there any kind of onLoad/onLoadComplete method? Because my app is crashing because of this.

@R4m0nz3r4
Copy link

R4m0nz3r4 commented Dec 20, 2022

I'm using a FlashList as example, but it uses the RecyclerListView internally. I believe that something like this should fix the behavior:

const [isComponentReady, setComponentReady] = useState(false);
const flashListRef = useRef<FlashList<GenericList>>(null);

useEffect(() => {
  if (isComponentReady)
    flashListRef.current?.scrollToIndex({
      index,
      animated: true,
    });
}, [index]);

useEffect(() => {
  setComponentReady(true);
}, []);

@giantslogik
Copy link

giantslogik commented May 6, 2024

Looking into the source code, i found two ways to avoid the error. (You only need one of these)

  1. Set the layoutSize prop. (works great especially if your items are a fixed size.)
    layoutSize={{ height, width }}

  2. Check if you can getLayout (and retry scroll if not)
    if (listRef.current?.getLayout(0) !== undefined) listRef.current?.scrollToIndex(i, false); else //....setup retry for later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants