Skip to content

FlatList: initialScrollIndex broken in v0.16 #2030

Closed

Description

@hizo

The problem
initialScrollIndex prop on FlatList stopped working from v0.16

How to reproduce
Simplified test case: https://codesandbox.io/s/nifty-hopper-44ntf

Steps to reproduce:

  1. open the above test case link
  2. observe an empty list with a scrollbar on the right (no signs of attempted scroll - the scrollbar is at the top of the list)
  3. scroll
  4. observe all items render at this point, with the scroll starting at the top of the list, instead of the provided index in initialScrollIndex prop

Expected behavior
FlatList renders items starting from the correct index provided in initialScrollIndex prop and the scrollbar shows correct position.

Environment (include versions). Did this work in previous versions?

  • React Native for Web (version): 0.16.3
  • React (version): 17.0.2
  • Browser: Google Chrome Version 90.0.4430.212

This worked in 0.15.x versions and below
Test case showcasing correct behaviour with rn-web v0.15.7: https://codesandbox.io/s/elegant-leaf-8yt3c

Activity

  1. changed the title [-]FlatList: initialScrollIndex broke in v0.16[/-] [+]FlatList: initialScrollIndex broken in v0.16[/+] on May 24, 2021
  2. hizo commented on Jul 27, 2021

    @hizo
    Author

    Any update on this please? @necolas

  3. sirpy commented on Aug 18, 2021

    @sirpy

    not working also on 0.17
    as a workaround it is possible to pass this method to the "ref" prop
    where selectedFeedIndex is the initial item

    const getFlatListRef = useCallback(
        flatList => {
          if (flatList) {
            flatList.scrollToIndex({ animated: false, index: selectedFeedIndex })
          }
        },
        [selectedFeedIndex],
      )
    
  4. added a commit that references this issue on Mar 23, 2022
    edec979
  5. added a commit that references this issue on Sep 13, 2022
    20edba5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug: react-nativeBug associated with upstream React Native vendor code

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions