-
Notifications
You must be signed in to change notification settings - Fork 40
Description
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