react-native-snap-carousel icon indicating copy to clipboard operation
react-native-snap-carousel copied to clipboard

onSnapToItem never gets called

Open mohammedmunaf opened this issue 5 years ago • 11 comments

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}
                />

mohammedmunaf avatar Jun 19 '19 13:06 mohammedmunaf

I am facing something similar in Desktop, but the difference is that on Android works OK. I have not tested on iOS yet.

Using "react-native-snap-carousel": "3.8.0"

Code:

...
changeTitle(index) {
  this.setState({
    slider1ActiveSlide: index
  });
}
...
          <Carousel
            ref={c => {
              this._carousel = c;
            }}
            data={data}
            layout="default"
            renderItem={this._renderItem}
            sliderWidth={viewportWidth}
            itemWidth={viewportWidth}
            onSnapToItem={index => this.changeTitle(index)}
            useScrollView
          />

adrian1388 avatar Jun 19 '19 14:06 adrian1388

I am facing something similar in Desktop, but the difference is that on Android works OK. I have not tested on iOS yet.

Using "react-native-snap-carousel": "3.8.0"

Code:

...
changeTitle(index) {
  this.setState({
    slider1ActiveSlide: index
  });
}
...
          <Carousel
            ref={c => {
              this._carousel = c;
            }}
            data={data}
            layout="default"
            renderItem={this._renderItem}
            sliderWidth={viewportWidth}
            itemWidth={viewportWidth}
            onSnapToItem={index => this.changeTitle(index)}
            useScrollView
          />

I found that this is the issue for me...

adrian1388 avatar Jun 19 '19 15:06 adrian1388

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

mohammedmunaf avatar Jun 19 '19 16:06 mohammedmunaf

I'm having the same issue and activeSlideOffset={2} didn't solve it. @adrian1388 Did you figure out a way to fix this?

cesar3030 avatar Jul 17 '19 00:07 cesar3030

@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}
                />

mohammedmunaf avatar Jul 23 '19 11:07 mohammedmunaf

@mohammedmunaf Thank you for your help! My problem came from the fact I was using the carousel in a bottom sheet component from the react-native-reanimated-bottom-sheet library. On Android the touch event was not captured because of the bottom sheet.

cesar3030 avatar Aug 01 '19 17:08 cesar3030

@mohammedmunaf Thank you for your help! My problem came from the fact I was using the carousel in a bottom sheet component from the react-native-reanimated-bottom-sheet library. On Android the touch event was not captured because of the bottom sheet.

I'm having the same error. What was the fix?

jrobber avatar Apr 21 '20 05:04 jrobber

@mohammedmunaf Thank you for your help! My problem came from the fact I was using the carousel in a bottom sheet component from the react-native-reanimated-bottom-sheet library. On Android the touch event was not captured because of the bottom sheet.

I'm having the same error. What was the fix?

https://github.com/archriss/react-native-snap-carousel/issues/541#issuecomment-514165668

munafmohammed avatar Apr 21 '20 06:04 munafmohammed

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

dohooo avatar Oct 08 '21 05:10 dohooo

Same issue today, please any suggestions on how to fix would be appreciated

tkud04 avatar Feb 13 '23 20:02 tkud04

useScrollView={true} solved the problem for me

taxidrivermeow avatar Aug 14 '24 20:08 taxidrivermeow