-
-
Notifications
You must be signed in to change notification settings - Fork 333
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
Carousel becomes blank when removing last item from data list #571
Comments
Thank you for providing the detailed context. I understand that you're experiencing an issue where the carousel becomes blank when the last item is removed from the data list. This issue seems to be similar to a few open issues in the react-native-reanimated-carousel repository, specifically issue #550 and issue #464. Based on the information from these issues, there are a couple of potential solutions you could try:
return (
<>
{
data.map((item, index) => {
const realIndex = computedRealIndexWithAutoFillData({
index,
dataLength: rawDataLength,
loop,
autoFillData,
});
const { negativeRange, positiveRange } = displayedItems;
const shouldRender = (index >= negativeRange[0] && index <= negativeRange[1])
|| (index >= positiveRange[0] && index <= positiveRange[1]);
if (!shouldRender)
return null;
return (
<BaseLayout
key={item.userId} // Use item.userId as the key
index={index}
handlerOffset={offsetX}
visibleRanges={visibleRanges}
animationStyle={customAnimation || layoutConfig}
>
{({ animationValue }) =>
renderItem({
item,
index: realIndex,
animationValue,
})
}
</BaseLayout>
);
})
}
</>
); This assumes that each item in the data array has a unique
<Carousel key={data.length} data={data} /> This workaround was found in a comment on issue #272 and has received positive feedback. Please try these solutions and let me know if they help resolve your issue. If not, we can continue to investigate further. Sources
|
Possible duplicate of #550 |
suggested solution doesn't work |
I didn't understand first approach, second approach is working , but someone claiming it isn't perfomant |
set key={data.length} and it's working on removing any item
|
Describe the bug
Removing last item from carousel data list will result in blank carousel. Similar issue to meliorence/react-native-snap-carousel#623 & #550.
To Reproduce
Create carousel with data list e.g [A, B, C], remove last item C from data list, the carousel will be blank.
Expected behavior
The carousel should render item B when item C is removed from data list.
Screenshots
If applicable, add screenshots to help explain your problem.
Versions (please complete the following information):
Smartphone (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: