Skip to content

Infinite scroll appending first item after the last item (infinite circular scroll) #193

@nabinkumarn

Description

@nabinkumarn

Hi, I want to achieve a behavior of infinite scroll with an array of data. After last item, first item should repeat on right side. On left side, if first item is selected, scroll is disabled to left but user can continue to scroll in loop in right side.

For this, I have tried to use onEndReached, appending data to array of previous data and it is working but issue will array will grow and cause performance issue, so tried to remove starting items before adding to end.
const handleEndReached = useCallback(() => { if (data?.contentList?.length > 0) { setContentList((prevList) => { const originalLength = originalContentLength.current; const newContent = [...data.contentList]; let updatedList = [...prevList, ...newContent]; const itemsToRemove = updatedList.length - maxLength; updatedList = updatedList.slice(itemsToRemove); return updatedList; }); } }, [data.contentList, setSelectedIndex]);

<SpatialNavigationVirtualizedList ref={listRef} style={styles.scrollView} data={contentList} renderItem={renderItem} itemSize={getItemSize} orientation={'horizontal'} scrollBehavior={'stick-to-start'} scrollDuration={400} additionalItemsRendered={10} onEndReached={handleEndReached} onEndReachedThresholdItemsNumber={5} getItemLayout={getItemLayout} />

Once I do this, I am not able to scroll and focus position is messed,

Has anyone tried to create like this? Can you suggest me how we can achieve this behavior with this package.
Any example code would help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions