react-nativereact-native-animatable

React Native Image Slider Animation


There are 4 images. Whenever I swap them, I want to have a smooth animated transition. How may I apply that in my current code?

Click here to view the code

Also please check out the 2nd screenshot. I don't want the left swap option to be active when there is no image. But it swaps 1 extra time and stops. What is wrong with my logic?

Here is the screenshot


Solution

  • Have a try with the below code:

    const handleSwipeLeft = () => {
        if (activeImg < totalImage - 1) {
            setActiveImage(currActive => currActive + 1)
        }
    }
    

    as the length greater than the index.