dohooo / react-native-reanimated-carousel

🎠 React Native swiper/carousel component, fully implemented using reanimated v2, support to iOS/Android/Web. (Swiper/Carousel)
https://react-native-reanimated-carousel.vercel.app
MIT License
2.64k stars 303 forks source link

Removing last item requires manual swipe to view previous item #550

Open garrettreed opened 5 months ago

garrettreed commented 5 months ago

Describe the bug Removing the last item in a non-looping carousel remains empty. Any swipe gesture is required to snap the carousel back to the previous item. Other items in the carousel correctly display the next available item when removed.

To Reproduce Below is a minimum reproducible example. Scrolling to the third item and pressing "Delete Me" shows the behavior.

function Example() {
  const windowWidth = useWindowDimensions().width;
  const [data, setData] = React.useState([1, 2, 3]);

  return (
    <Carousel
      width={windowWidth}
      loop={false}
      data={data}
      renderItem={({ item }) => (
        <View style={{ borderWidth: 1, flex: 1 }}>
          <Text>Item {item}</Text>
          <Pressable
            onPress={() => {
              setData(prev => prev.filter(i => i !== item));
            }}
          >
            <Text>Delete Me</Text>
          </Pressable>
        </View>
      )}
    />
  );
}

Expected behavior When the last item in the carousel is removed, it should show the new last item.

Screenshots https://github.com/dohooo/react-native-reanimated-carousel/assets/4079858/66910188-1d83-4ed2-bad3-3a6236e0e275

Versions (please complete the following information):

Smartphone (please complete the following information):

Vladislava9009 commented 2 months ago

Have the same