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.

Items are jumping on initial load

See original GitHub issue

Is this a bug report, a feature request, or a question?

Bug Report

Have you followed the required steps before opening a bug report?

(Check the step you’ve followed - put an x character between the square brackets ([]).)

Have you made sure that it wasn’t a React Native bug?

Yes

Is the bug specific to iOS or Android? Or can it be reproduced on both platforms?

iOS. Untested on Android.

Is the bug reproductible in a production environment (not a debug one)?

Yes

Environment

(Write your answer here.)

Expected Behavior

On load, the items are expected to load such that if an item is at index 0, it is the only one visible. Even if the item hasn’t loaded yet, it should still be the index displayed on screen.

(Write what you thought would happen.)

Actual Behavior

Currently, on initial load, item at index 0 is not the first element that a user sees. Currently, a user will see item at index 4, and then it jumps back to index 0.

(Write what happened. Add screencasts/screenshots!)

Reproducible Demo

A video of the bug here: https://imgur.com/K4K4WhJ

The code I’m using looks like this:

<Carousel
                                   sliderWidth={screenWidth}
                                   sliderHeight={125}
                                   itemWidth={screenWidth * .4}
                                   data={categories[category]['items']}
                                   renderItem={(thing) => this.renderItem({thing, category})}
                                   inactiveSlideScale={1}
                                   inactiveSlideOpacity={1}
                                   hasParallaxImages={false}
                                   loop={true}
                                   loopClonesPerSide={2}
                                   onSnapToItem={(i) => this.updateIndex(i, category)}
                                   enableSnap={false}
                                   enableMomentum={true}
                                   activeAnimationType="spring"

                               />

renderItem is a simply button:

renderItem({ thing, category }){
     let { item, index } = thing
     let itemLink = () =>  this.props.navigation.navigate({
         routeName: 'Item', 
         params: { item: item.id, itemData: item, category },
         key: item.id
     })
     return(
         <TouchableOpacity key={item.id} onPress={itemLink} key={item.id} style={{ borderRadius: 10, width: screenWidth * .4, marginHorizontal: 5 }}>
         <Transition shared='itemImage'>
             <Image source={{ uri: item.image }} style={{ borderRadius: 10, height: 125, width: screenWidth * .4 }} />
         </Transition>
         <Text style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>{item.name}</Text>
     </TouchableOpacity>
     )
 }

Steps to Reproduce

This is on the initial mounting/loading of the component. To reproduce, if you use the above code and replace my logic for the image source with your own, you should be able to see how it behaves.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:7

github_iconTop GitHub Comments

2reactions
pratik72commented, Nov 22, 2019

Facing same issue. After first time load, user slide 2 or 3 index and suddenly it set 0 index like init load. But still waiting for solution. 😞

0reactions
dohooocommented, Oct 8, 2021

Sorry, please allow me to advertise for my open source library! ~ I think this library react-native-reanimated-carousel will solve your problem. It is a high performance and very simple component, complete with React-Native reanimated 2

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to stop content jumping when images load? - ITNEXT
How to stop content jumping when images load? Images are widely used in most websites, web apps and PWAs, have a look ...
Read more >
Content Jumping (and How To Avoid It) | CSS-Tricks
The good news is that it's fixable. Luckily, modern browsers don't perform initial render until the style sheets have finished loading, which ...
Read more >
Why does my site jump on first load? [closed] - Stack Overflow
The reason for the jump is because the <div id="header"> gets the class .affix-top with JavaScript and in the first load there is...
Read more >
Ways To Reduce Content Shifting On Page Load
As you can see, there are many solutions for avoiding the jump effect on page load. Yes, implementing all of these techniques would...
Read more >
Header jumping slightly to left on page load - Support - Themeco
First, check for CSS that causes this movement because Save or back up your CSS then remove it for testing. Let us know...
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