meliorence / meliorence/react-native-snap-carousel

Items are jumping on initial load

Open
#583 7 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
10.5k
Forks
2.3k
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied Carousel configuration and reviewing the linked video, focusing on initial mounting with loop enabled, two clones per side, and snapping disabled. Trace why index 4 appears before index 0 on iOS; done means index 0 remains the first visible item during initial loading without regressing carousel behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react-native
Domain
frontend, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.