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.

onSnapToItem never gets called

See original GitHub issue

Using “react-native-snap-carousel”: “3.7.5” Testing on iOS

Here is my code

<Carousel
                    ref={(c) => { this._carousel = c; }}
                    vertical={true}
                    data={["1", "2", "3", "4", "5", "6", "7", "8"]}
                    renderItem={({ item, index }) =>

                        <TouchableOpacity
                            style={{ flex: 1, backgroundColor: "transparent" }}
                            onPress={() => { this._carousel.snapToItem(index) }}>
                            <Text
                                style={{
                                    height: 30,
                                    textAlignVertical: 'center',
                                    flex: 1,
                                    textAlign: 'center',
                                    fontSize: 16
                                }} key={"money" + item}>{item}</Text>
                        </TouchableOpacity>
                    }
                    onSnapToItem={(index) => {
                        console.log("Moved to=====> " + index)
                        alert(index)
                    }}
                    inactiveSlideOpacity={0.4}
                    inactiveSlideScale={0.9}
                    enableSnap={true}
                    removeClippedSubviews={false}
                    autoplay={false}
                    sliderHeight={80}
                    sliderWidth={90}
                    itemHeight={30}
                    itemWidth={90}
                />

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

13reactions
mohammedmunafcommented, Jul 23, 2019

@cesar3030 I was facing this issue while I scroll fast on Android. I resolved it by adding

activeSlideOffset={2}
enableMomentum={true}
decelerationRate={0.9}

Here is my final code

<Carousel
                    ref={(c) => { this._carousel = c; }}
                    layout={'default'}
                    vertical={true}
                    data={this.props.data ? this.props.data : []}
                    renderItem={this.renderItem.bind(this)}
                    onSnapToItem={this._onSnapToItem.bind(this)}
                    sliderHeight={this.props.sliderHeight}
                    inactiveSlideOpacity={0.4}
                    inactiveSlideScale={0.9}
                    activeSlideOffset={2}
                    lockScrollWhileSnapping={true}
                    enableSnap={true}
                    enableMomentum={true}
                    decelerationRate={0.9}
                    removeClippedSubviews={false}
                    autoplay={false}
                    itemHeight={this.props.itemHeight}
                    initialNumToRender={this.props.data ? this.props.data.length : 0}
                    firstItem={0}
                />
2reactions
mohammedmunafcommented, Jun 19, 2019

Hi folks, Seems very cosmetic bug. Setting activeSlideOffset={2} solved my issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

onSnapToItem never gets called · Issue #541 - GitHub
I am facing something similar in Desktop, but the difference is that on Android works OK. I have not tested on iOS yet....
Read more >
Recording user interactions in React Native / Snap Carousel
onSnapToItem is triggered everytime I change from one slide to another. ... Hmm hard to say but if you have an async/await call...
Read more >
React Native carousel with react-native-snap-carousel
Create a carousel in a React Native mobile application with a Tinder-style swipe animation using the react-native-snap-carousel package.
Read more >
snap-carousel-onSnapToItem - Expo Snack
snap-carousel-onSnapToItem. No description. Open with Expo Go. Open in editor. Need Expo? Don't have the Expo Go? Download the app to try this...
Read more >
react-native-snap-carousel takes a lot of time to render photos
... sliderWidth={sliderWidth} itemWidth={itemWidth} activeSlideAlignment={'center'} onSnapToItem={index => setActiveSlide(index)} />).
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