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.

Scrolling between components is smooth in simulator but laggy on real device

See original GitHub issue

Describe the bug I’m using this package to create full page horizontal view scrolling between components. As the title said, the scrolling is smooth when I test it in a simulator (both iOS and Android). However, when I test it on a real device, I notice that it is laggy when I start to do the scrolling.

Is it because this package is suitable for images, but not for full page component? Or how should I optimise my code to make it smoother?

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

// import statements

const {height: PAGE_HEIGHT, width: PAGE_WIDTH} = Dimensions.get('window');
const activeOffsetX = {activeOffsetX: [-10, 10]};

const App = () => {
  const resultRef = useRef(null);
  const [currentSide, setCurrentSide] = useState('M');
  const [isVertical] = useState(false);

  // other code

  // Base options for <Carousel />
  const baseOptions = isVertical
    ? {
        vertical: true,
        height: PAGE_HEIGHT,
        width: PAGE_WIDTH,
      }
    : {
        vertical: false,
        height: PAGE_HEIGHT,
        width: PAGE_WIDTH,
      };

 // other code

  return (
    <SafeAreaView style={styles.container}>
      {isLoading && !isLiveStarted ? <FullScreenLoading /> : null}
      <AppTitle />
      {result.length === 0 ? (
        <Carousel
          {...baseOptions}
          data={c}
          defaultIndex={0}
          panGestureHandlerProps={activeOffsetX}
          ref={blankResultRef}
          renderItem={({index}) => {
            return (
              <BlankResultScreen
                key={index}
                index={index}
                bgColor={c[index].color}
                hasLetter={c[index].hasLetter}
                isBlackText={c[index].isBlackText}
                isGreenText={c[index].isGreenText}
                name={c[index].name}
                source={c[index].image}
              />
            );
          }}
        />
      ) : (
        <Carousel
          {...baseOptions}
          data={c}
          defaultIndex={0}
          onSnapToItem={index => setCurrentSide(c[index].code)}
          pagingEnabled={false}
          panGestureHandlerProps={activeOffsetX}
          ref={resultRef}
          renderItem={({index}) => {
            return (
                <ResultScreen
                  key={index}
                  index={index}
                  bgColor={c[index].color}
                  companyCode={c[index].code}
                  hasLastRow={c[index].hasLastRow}
                  hasLetter={c[index].hasLetter}
                  hasLiveVideo={c[index].hasLiveVideo}
                  isBlackText={c[index].isBlackText}
                  isGreenText={c[index].isGreenText}
                  name={c[index].name}
                  source={c[index].image}
              </>
            );
          }}
        />
      )}
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

export default codePush(codePushOptions)(App);

Expected behavior Scrolling between every view should be smooth on real devices.

Screen record https://user-images.githubusercontent.com/105196702/175454414-e4ec3a40-a6ff-4bb9-bf6e-b08710f43220.mp4

Versions (please complete the following information):

  • react: v17.0.2
  • react-native: v0.68.2
  • react-native-reanimated: v2.8.0
  • react-native-reanimated-carousel: v3.0.0
  • react-native-gesture-handler: v2.4.2

Smartphone (please complete the following information):

  • Device: iPhone11
  • OS: iOS15.4.1

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
oliverloopscommented, Jun 29, 2022

Thanks for share!. yes I notice the same behavior when the swipe gesture is slower there is a noticeable FPS dropping. Let’s me see what’s happening under the hood and see If I can fix it quickly

2reactions
hy-atozcommented, Jun 29, 2022

Hi @hy-atoz 👋, I notice that you’re not using the windowSize prop. I recommend you to use it as a first solution when you encounter with some of this performance issues that produces laggy transitions, this props helps you rendering some of the views avoiding overloading and increasing performance when you have multiple elements. The library can handle complex layouts eg. grouped components, multiple rendered elements in the same view etc., we actually called this complex carousel, there’s a great possibility that your own full page components aren’t causing the issue.

I was doing some intensive elements rendering inside the core <Carousel /> component changing the windowSize prop parameters and I recommend you to use values between 3 - 5.

I’ll hope this helps.

Hi @oliverloops, thank you for the suggestion! I’ve tried adding the windowSize prop, but the problem still exist.

As for now, when I scroll through the carousel very quickly, the performance is excellent, as you can see in the screen record. But when I do it slower, you can see that it is not as smooth as when the movement is fast.

Do you have any idea why is this happening?

https://user-images.githubusercontent.com/105196702/176452550-7e28beec-52a6-4292-bbaa-e5733687c20a.mp4

Read more comments on GitHub >

github_iconTop Results From Across the Web

iOS simulator scrolling on Apple S… | Apple Developer Forums
It lags, so I can drag with the Magic Mouse, but the swipe gesture is not recognised properly.
Read more >
scrollview scrolls smooth in simulator but not in device?
The fact that it is running slower on the device (potentially several times slower) is completely normal. The simulator is not cycle ...
Read more >
Common bugs in React Native ScrollView and how to fix them
React Native's ScrollView component is ubiquitous, but its implementation can sometimes lead to mistakes. Learn what to look out for here.
Read more >
Momentum Scrolling on iOS Overflow Elements - CSS-Tricks
You might think that any element with scrolling would have this behavior as well, but it doesn't. You can add it back with...
Read more >
React Native Scrollview 101: The Best Practices Guide - Waldo
When mobile apps abruptly clip off content from the screen, it's a sign of bad UX for developers. Moreover, not being able to...
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