-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
[FlatList] render issues using scrollToIndex
on componentDidMount
#13202
Comments
👍 (plus 1) from me. I'd agree, the issue does seems to lie with trying to scroll to an index/contentOffset outside the initial render window. Given the 'initialNumToRender' renders the items starting in 0th index in the provided array of items. As a user of the component, for example, would it make any sense to be abled to specify the 'initialNumToRender' as well as the starting index of the items to render and either the component can manage the appropriate starting contentOffset or this can be done externally? @sahrens mentioned that the initialNumToRender was a pull to refresh optimisation, so I'm not sure. @conrad-vanl : interesting find with the onScroll event. |
@conrad-vanl: the reason your example wasn't working in sketch is that FlatList is in pre-release in 0.43 and AFAIK sketch is currently bundling 0.42. |
Not sure. The bug here definitely has to do with the bad values being sent in the |
@joshyhargreaves I came across that issue as well. For me, it had to do with the Potentially related to #8624 |
@conrad-vanl funnily enough, it looks like Just out of interest, if you call |
@joshyhargreaves no, but Will have to check on your other Q |
@conrad-vanl thanks for clarifying, much appreciated. |
Yes I think it makes sense to add some Are you providing There should be logic to promote the cell rendering priority to bypass runAfterInteractions if they are close enough to or inside the viewport - perhaps that logic is broken? Or you are just doing other heavy JS computation that's blocking it up? |
Oh sorry, looks like you are providing getItemLayout. I'll take a look. |
@sahrens the Again, that's a different issue that was fixed (for me, atleast) by making sure |
Yep, does look like a couple of seperate issues! @sahrens it looks like I've got a separate problem with |
@conrad-vanl: thanks for the heads up about @sahrens fixing the So I think you're right, as a result of these items being rendered with a low priority not high I think`initialScrollIndex' would make a lot of sense :). I'd be interested to see what the logic would might look like, so will have a look out of interest! Thanks a lot. |
@conrad-vanl I'm actually seeing the same issue as you, although intermittently. |
@conrad-vanl #13316 Even the most basic example has the same problem. |
I got this problem to, I found a little hack to avoid this issue until it's fixed. Just add a sleep() like function before scrollToIndex like
|
@ludovic-coder Your solution works! The only caveat is that However, the support for a |
@irrigator Definitely, |
scrollToIndex
on componentDidMount
scrollToIndex
on componentDidMount
@irrigator additionally, using |
@joshyhargreaves You are right. And that's why this approach is only a workaround. Also, you do need to put the |
Thank you @sahrens |
How to upgrade react-native to master branch version? Because only in master include this method |
@MrChe you can point your Another option is pulling |
@sahrens First of all I appreciate for your work(initialScrollIndex) sahren, but I still got white space till i manually scroll the contents.. i'm using React Native Router Flux on my app. Is it related with navigation library that I'm using? and i also set false RemoveClippedSubviews that you suggested as a solution in other issues about rendering bug. |
@mnkang89 @sahrens I am actually also seeing the exact same behaviour with React Native router flux and initialScrollIndex. I'm hoping to be able to push a project reproducing the issue in the next couple of days. Unless @mnkang89 you perhaps beat me to it? A repro project from anybody would be a big help! I wonder if we would see this issue with other JS navigators too; I would guess it's not specific to router flux. @mnkang89, have you tried setting removeClippedSubviews to false? Unfortunately for me the problem still persists. |
@joshyhargreaves yes i also tried setting removeClippedSubviews to false but i still got white space.. |
Weird, sounds like something specific to react native flux router...perhaps the layout and visibleHeight measurement are getting messed up? Can you try logging the scrollMetrics everywhere they are updated in VirtualizedList along with the function that updates it, and log when the scrollTo call is made, and let me know what's printed? Also, can you try increasing the timeout for initialScrollIndex and see if that fixes it? Try maybe 17ms and 200ms. |
Annoyingly the 'blank content until scroll' seems to happen sporadically 'come and go' a few times in succession and not again for a while (I'm not really sure what the varying factors causing it, for me at least!). I haven't managed to recreate it in the last hour or so. But here are are the the tl:dr is that with a I have also created a separate project with |
I probably should have just set it up to wait for onLayout instead of doing the setTimeout. You said that visibleLength is correct with a value of 17 - does everything render correctly as well in that case? Or are there still bugs? |
Damn, it does look like a consistent reproducible example would be super useful at this point. I remember seeing a couple of issues where people had posted some examples that could be helpful, I'll test a few out and post back with anything interesting. I guess we are still speculating slightly at this point too! With 17ms, as far as I can tell, no visual defects; this is in a horizontal viewPager like scenario. |
@sahrens I totally agree with you. I think it is more solid to set it up to wait for onlayout rather than to use setTimeout. |
@mnkang89 just to sanity-check, does adding a timeout of 17ms to VirtualizedList fix the issue for you? |
@mnkang89 thank you for that. Hmm, that is interesting. What can we say about the order in which onLayout is being called here, do you still think it's still being called after the componentDidMount 'scrollTo' callback? |
@joshyhargreaves No problem well I've tried logging scrollmetrics just now. hmm....am I doing something wrong? |
@mnkang89, as far as I'm aware, there's a race condition when printing out objects in memory in the chrome console (if they're updated soon after the console.log) itself. You can either Regarding the timeout values, I'm not very sure myself, hopefully @sahrens might have some more insight :S. |
@mnkang89, for some reason your comment isn't listed here?
Wow, I may have made a bit of an oversight too. I have scrollViews a horizontal FlatList and your experience would suggest that they should have I think there's a lot to be said about using a pure native navigation solution at this point assuming this is part of the issue. facepalm |
Sorry to interfere. I have a very serious problem with FlatList. When the coup is wrong, the calculation is up to the element, here is an example video - http://take.ms/DHdyO |
@joshyhargreaves yeah actually I deleted my comment by mistake lol.. anyway set both of flatlist's removeclippedsubviews to false does work for me haha. I'm not sure it is only navigation problem. cause I saw similar issues in react-navigation also. like these react-navigation/react-navigation#1338 |
|
Hi @sahrens, any advice for navigating the FlatList that have variable height? |
Hi mine fixed by giving |
…Index not rendering first item until user scroll (see description) Follow issue here: facebook/react-native#13202 initial state of scrollindex can be removed, as well as the timeout + ref
why this is closed? This solution do not solve the problem!! |
Description
Running into an inconsistent bug when trying to use
scrollToIndex
oncomponentDidMount
. Essentially, if theindex
I'm scrolling to is outside of theinitialNumToRender
, it doesn't get rendered until I start manually scrolling. You can see the behavior in this gif:(apologies, just realized it is nearly 40mb in size....)
I have tracked the error down to the
onScroll
handler being called with inaccurate data:Which sets the
visibleLength
andcontentLength
properties to zero.This appears that it could be a problem with
ScrollView
itself, but I'm not sure. As soon as I start manually scrolling, theonScroll
handler fires with the correct properties, and the view content renders.Reproduction Steps and Sample Code
I couldn't get sketch.expo to work, but this example reproduces the issue for me on a fresh React-Native project: https://gist.github.com/conrad-vanl/41e2abb244d0b6e1bd952bd4ff4b3cd7
Essentially:
And I also have the repo that produced the above GIF as well: https://github.com/conrad-vanl/rn-flat-list-tests
Solution
None yet. Finally confident that I'm reproducing the issue consistently enough. I believe it might be an issue with
ScrollView
but I'm not familiar enough (yet) with the intricacies here, so figured I'd post the issue while I continue to track issue origin.Additional Information
The text was updated successfully, but these errors were encountered: