question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

image sliding not smooth when have a lot of images

See original GitHub issue

Describe the bug we use this library in our product detail, and our product images has minimum 10 images. when press in and sliding the animation is not smooth, FPS drop to 20-30 (depends on different specs)

i tried different setup the issue still occur. i tried with only 2-3 image the issue is gone, FPS consistent 50+ i tried with snap-carousel to compare the performance, and its better. FPS drop minimum 44 and average 50+. (you can see video below)

To Reproduce Steps to reproduce the behavior, here is my code:

const CarouselBanner = (props) => {

  ...

  const renderItem = useCallback(({ index, item }) => {
    // console.log('renderItem');
    return (
      <Touchable
        key={index}
        onPress={() => {
          if (item.alt_links) _callbackBanner(item.id, item.title, item.alt_links)
        }}
      >
        <AsyncImage
          source={{ uri: item.img_mobile }}
          style={style}
          placeholderColor={Colors.colorLevel3}
        />
      </Touchable>
    );
  }, [data]);

  const Indicator = memo(props => {
    // console.log('Indicator');
    const { animValue, index, length } = props;

    const animStyle = useAnimatedStyle(() => {
      let inputRange = [index - 1, index, index + 1];
      let outputRange = [-width, 0, width];

      if (index === 0 && animValue.value > length - 1) {
        inputRange = [length - 1, length, length + 1];
        outputRange = [-width, 0, width];
      }

      return {
        transform: [{
          translateX: interpolate(
            animValue.value,
            inputRange,
            outputRange,
            Extrapolate.CLAMP
          )
        }],
      };
    }, [animValue, index, length]);

    return (
      <View key={`indicatorBanner_${index}`} style={styles.indicator}>
        <Animated.View style={[styles.active, animStyle]} />
      </View>
    );

  }, () => true);

  const _onProgressChange = useCallback((offsetProgress, absoluteProgress) => {
    // console.log('offsetProgress, absoluteProgress', offsetProgress, absoluteProgress);
    if (data.length === 2 && absoluteProgress >= 2) {
      return progressValue.value = absoluteProgress - 2;
    } else return progressValue.value = absoluteProgress;
  }, [])


  return (
    <View key='CarouselBanner'>
      <Carousel
        key='CarouselBanner'
        width={widthCarousel}
        height={heightCarousel}
        data={data}
        autoPlay={autoPlay}
        autoPlayInterval={autoPlayInterval}
        // windowSize={windowSize}
        onProgressChange={_onProgressChange}
        renderItem={renderItem}
        scrollAnimationDuration={300}
        loop={false}
      />

      <View key='pagination' style={styles.pagination}>
        {data.map((record, index) => {
          return <Indicator key={index} index={index} length={data.length} animValue={progressValue} />;
        })}
      </View>
    </View>
  );
};

Expected behavior smooth animation when slide

Screen record react-native-reanimated-carousel https://user-images.githubusercontent.com/17826213/174019683-42f2976e-57b4-474f-a143-7435c2f12028.mp4

react-native-snap-carousel https://user-images.githubusercontent.com/17826213/174015388-cb86d3ff-dca7-4549-86fc-b48ceca64b86.mp4

Versions (please complete the following information):

  • react: v17.0.1
  • react-native: v0.64.3
  • react-native-reanimated: v2.2.0
  • react-native-reanimated-carousel: v2.4.0
  • react-native-gesture-handler: v1.10.3

Smartphone (please complete the following information):

  • Device: oneplus 5, zenfone 5
  • OS: android 9 & 10

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
oliverloopscommented, Jun 19, 2022

Hi @hotaryuzaki, I reproduce your example and I recommend you to set a value for the windowSize prop. loop prop just enables you to scroll in the opposite direction if is true (eg. if you have 100 items you can scroll from 0 -> 99 with loop={true}) . with this in mind having windowSize enabled helps rendering just a couple of elements of any large list, keeping a good frame rate (between 56 - 60 FPS). I was playing around with the windowSize param and found better results giving it a value between 3 -> 5. I recommend you to try this with your own implementation and compare it against the base use case.

0reactions
mahaaoocommented, Jun 22, 2022

I think this problem is probably caused by pagination, Remove pagination and try again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Image slider is choppy - javascript - Stack Overflow
In summary: I have a DIV with 4 images in a row, each image is 100% the width of the page. I use...
Read more >
SMOOTH Image Slide in Premiere Pro - YouTube
A tutorial on how to make images slide smoothly in Premiere Pro cc 2019. This is a smooth image push or slide transition/animation....
Read more >
Gallary Slides not smooth sliding - with white in transition
Hi, need some help with my gallary slider. If you can see, during the transition between two pictures you can see a white...
Read more >
Image Carousels and Sliders: Why You Shouldn't Use Them ...
Nielsen concluded that image carousels get ignored. Notre Dame University tested it, too. Only the first slide got some action (1%!). Other slides...
Read more >
Image Editing 101: Fixing Common Problems - GCF Global
Try this! Drag the slider in the interactive below to adjust the sharpness of the image. Try to make the image look crisp...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found