-
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 scrollToIndex scrolls to wrong place when used for the first time #19441
Comments
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions. |
Replying to stale bot - The issue has not been fixed. The snack looks the same and our app still suffers from this bug. |
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions. |
Still a bug |
I think this is fixed in the latest release, at least I can't reproduce it in the latest version of the snack using those steps - @amcvitty any chance you can give it a re-run? |
@orta Thanks for taking a look. I just reran the snack and I still see the same behavior. The first click scrolls D2 to the left of the screen, subsequent clicks scroll it to the center as expected Here's me running it with expo 32.0.0: |
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions. |
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information. |
When using a FlatList to display a small number of Buttons, the first time I call scrollToIndex, it miscalculates the position to put things on screen relative to the viewPosition specified.
Environment
Environment:
OS: macOS High Sierra 10.13.4
Node: 9.8.0
Yarn: 1.5.1
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.3.1 Build version 9E501
Android Studio: Not Found
Packages: (wanted => installed)
react: 16.3.1
react-native: 0.55.2
Steps to Reproduce
Load this snack: https://snack.expo.io/@amcvitty/flatlist-scroll-bug
This app simply scrolls the appropriate red box in the FlatList at the top to the center of the view when you click the corresponding button in the list below.
Expected Behavior
The first click should take the D2 box to the center
Actual Behavior
The first click ignores the viewPosition, unless the user does an actual scroll before the first call to scrollToIndex.
My debugging
I did a bit of debugging and the reason seems to be that
this._scrollMetrics.visibleLength
in VirtualizedList has been incorrectly set to 0 in a call toonScroll
that happens after onLayout (when it is set correctly), but before any user interaction. The list receives a scroll event with all zeros, and specifically on this line:VirtualizedList.js:1267:
let visibleLength = this._selectLength(e.nativeEvent.layoutMeasurement);
the layoutMeasurement is 0.
Since the visibleLength is used in onScrollToIndex to calculate the appropriate scroll offset, the calculation is incorrect.
Scroll events triggered by user action have real event content and so the layoutMeasurement is reset correctly (to 375 on my iphone 7).
The text was updated successfully, but these errors were encountered: