You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to unit test a component that uses FlashList but when I scroll to an item, it doesn't change items being rendered.
My test renders a list with 4 items but only the first 3 are rendered because the list is 900px high and each item is 300px high.
Scrolling down with the FlashList function scrollToIndex() does not change the items rendered on screen.
Note: I do see the expected y value for each item if I log out flashListRef.current?.rlvRef?.getLayout(scrollIndex) (0 for item 1, 300 for item 2, 600 for item 3 and 900 for item 4)
Expected behavior
After scrolling down item 4 should be rendered
To Reproduce
interfaceTestItem{id: number;text: string;}constTEST_DATA=[{id: 1,text: 'one'},{id: 2,text: 'two'},{id: 3,text: 'three'},{id: 4,text: 'four'},]interfaceTestItemProps{id: number;text: string;}constTestItem=({text}: TestItemProps)=>{return(<Boxheight={300}><Text>{text}</Text></Box>)}constTestComponent=()=>{constflashListRef=useRef<FlashList<TestItem>>(null);const[scrollIndex,setScrollIndex]=useState(0);constrenderItem=useCallback(({item})=>{return(<TestItemid={item.id}text={item.text}/>);},[]);constscrollDown=useCallback(()=>{console.log('Scrolling down',flashListRef.current?.rlvRef?.getLayout(scrollIndex));flashListRef.current?.scrollToIndex({index: scrollIndex+1});setScrollIndex(scrollIndex+1);},[flashListRef,setScrollIndex,scrollIndex]);//Container height is hard coded to 900 in "@shopify/flash-list/jestSetup"return(<Box><Boxheight={900}><FlashListref={flashListRef}data={TEST_DATA}estimatedItemSize={300}renderItem={renderItem}/></DSBox><DSButtononPress={scrollDown}>ScrollDown</DSButton></DSBox>)}describe('MyComponent',()=>{it('should render item 4 after scrolling',async()=>{render(<TestComponent/>);constscrollDownButton=screen.getByRole('button');fireEvent.press(scrollDownButton);fireEvent.press(scrollDownButton);fireEvent.press(scrollDownButton);awaitwaitFor(()=>{expect(screen.getByText('four')).toBeTruthy();});});})
Platform:
iOS
Android
Environment
1.6.3
The text was updated successfully, but these errors were encountered:
robianmcd
changed the title
List items are not rendered after scrolling in unit test
New list items are not rendered after scrolling in unit test
Jan 23, 2025
Current behavior
I'm trying to unit test a component that uses FlashList but when I scroll to an item, it doesn't change items being rendered.
My test renders a list with 4 items but only the first 3 are rendered because the list is 900px high and each item is 300px high.
Scrolling down with the FlashList function scrollToIndex() does not change the items rendered on screen.
Note: I do see the expected
y
value for each item if I log outflashListRef.current?.rlvRef?.getLayout(scrollIndex)
(0 for item 1, 300 for item 2, 600 for item 3 and 900 for item 4)Expected behavior
After scrolling down item 4 should be rendered
To Reproduce
Platform:
Environment
1.6.3
The text was updated successfully, but these errors were encountered: