meliorence / react-native-snap-carousel

Swiper/carousel component for React Native featuring previews, multiple layouts, parallax images, performant handling of huge numbers of items, and more. Compatible with Android & iOS.
BSD 3-Clause "New" or "Revised" License
10.33k stars 2.28k forks source link

Swiper freezes on second slide. #392

Closed dpogoda closed 5 years ago

dpogoda commented 6 years ago

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

Bug report

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

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?

Both iOS and Android

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

Yes.

Environment

software version
react 16.5.0
react-native 0.56.1
react-native-snap-carousel 3.7.3
Target Android (6.0)
Target iOS (9.0)

Expected Behavior

The swiper should be swipeable. If downgrading and fixing to react-native-snap-carousel 3.7.2 it works as expected.

Actual Behavior

After updating the yarn.lock file, the swiper broke in our app. We could swipe to the second slide, but then it froze. We could neither slide forward nor backward. Interactions (e.g. links) on the current slide still work.

Reproducible Demo

Unfortunately I couldn't reproduce this bug in a minimal app. Everything worked fine. I'll continue to work on a reproduction and update this issue.

Does anybody else have similar problems or a setup where the carousel breaks with the latest react-native-snap-carousel version? I'd appreciate if someone could confirm the issue or help me resolve it.

bd-arc commented 6 years ago

Hi @dpogoda,

The bug might be linked to PR #390. Does it work properly if you remove the added line?

dpogoda commented 6 years ago

@bd-arc Thanks for the fast reply. Yes in fact deleting that line fixes the issue :)

bd-arc commented 6 years ago

Well, I should have tested the PR myself... Ok, I'll try and fix it as soon as I can.

Thanks for the feedback ;-)

dpogoda commented 6 years ago

@bd-arc Thank you for this amazing react native component :-)

bd-arc commented 6 years ago

@dpogoda Should be fixed in version 3.7.4 ;-)

benobab commented 6 years ago

Hi! The issue is still present in the 3.7.4 unfortunately :/

bd-arc commented 5 years ago

@benobab Damn! Could you share the configuration of your carousel?

benobab commented 5 years ago

Thanks for the reply!

Tell me if the code below is enough

                          <Carousel layout={'stack'} 
                                    data={ENTRIES}
                                    renderItem={this._renderItem}
                                    sliderWidth={sliderWidth}
                                    itemWidth={itemWidth}
                                    hasParallaxImages={false}
                                    firstItem={this.state.sliderActiveSlide}
                                    inactiveSlideScale={0.95}
                                    inactiveSlideOpacity={0.7}
                                    containerCustomStyle={styles.slider}
                                    contentContainerCustomStyle={styles.sliderContentContainer}
                                    loop={true}
                                    autoplay={false}
                                    // autoplayDelay={500}
                                    // autoplayInterval={3000}
                                    onSnapToItem={(index) => this.setState({ sliderActiveSlide: index }) }
                                />
benobab commented 5 years ago

The problem doesn't appear in the default mode.

bd-arc commented 5 years ago

@benobab This is interesting. Have you been able to isolate the prop responsible for the bug appearance then?

ZyphiraZircon commented 5 years ago

I am also encountering a similar issue, however it's only appearing on Android. The slider is unable to be moved when swiping. Autoplay seems to work, and the elements are clickable, just swiping seems to be busted.

My configuration:

<Carousel
    ref={(c) => { this._carousel = c; }}
    data={this.props.items}
    renderItem={this.singleItem}
    sliderWidth={Dimensions.get('window').width}
    itemWidth={Dimensions.get('window').width * 0.4}
    inactiveSlideScale={0.7}
    loop={true}
    enableSnap={true}
/>
bd-arc commented 5 years ago

@benobab @Zyphxion Can you tell me if this works properly when you use version 3.7.2?

harrisonlo commented 5 years ago

Not to complicate things further, but I encounter a similar issue which only happens on iOS, the third swipe would freeze...

Let me try to play around and update you guys here

bd-arc commented 5 years ago

@harrison0723 Same question: does it work properly if you use version 3.7.2?

harrisonlo commented 5 years ago

@bd-arc Nope, same issue with 3.7.2 for me

bd-arc commented 5 years ago

@harrison0723 Damn! If you could put up a Snack example that reproduces the issue, it would be great ;-)

bd-arc commented 5 years ago

This has been fixed in version 3.7.5 thanks to @ifsnow. Kudos to him!

harrisonlo commented 5 years ago

For anyone who still seems to have a similar issue, removeClippedSubviews={false} might solve your problem.

harisbaig100 commented 3 years ago

loopClonesPerSide={data.length} this prop is by default '3', setting it to length of the data will solve the stuck issue.

brambang commented 3 years ago

in terms of performance which is better? removeClippedSubviews={false} or loopClonesPerSide={data.length}

removeClippedSubviews set to false would impact performance in flatlist loopClonesPerSide to data.length would make 3 times images load

UPDATE: both of that not works

mustafaaii commented 3 months ago

I was getting this issue in React JS and React Native. However, I found a strange solution to this. If you put Swiper in a component and activate it at the first startup, the problem is solved, the example is below.

const Carousel = ({ data }: any) => {

        return (
            <>
                <Swiper autoplay={true} loop={true} showsButtons={false} showsPagination={false} style={{ height: 330 }} removeClippedSubviews={false}>
                    {
                        (Media(data.filter((f: any) => { return (f.type === type && f.page === page && f.position === position) })) || []).map((d: any, x: number) => {
                            return (
                                <View key={`banner-${d.id}-list-${x}`}>
                                    <TouchableOpacity onPress={() => { Linking.openURL(d.url); }}>
                                        <Image source={{ uri: `https://ik.imagekit.io/tey21emoa/banner/${d.blob}` }} style={{ resizeMode: "stretch", height: 330, width: "100%", borderRadius: 8, borderWidth: 1, borderColor: "#dee2e6" }} />
                                    </TouchableOpacity>
                                </View>
                            )
                        })
                    }
                </Swiper>
            </>
        )
    }