alexbrillant / react-native-deck-swiper

tinder like react-native deck swiper
ISC License
1.56k stars 464 forks source link

The swipe functionality does not work on the subsequent cards after swiping the first card. #395

Open omercandemir opened 1 year ago

omercandemir commented 1 year ago

The swipe functionality does not work on the subsequent cards after swiping the first card. I encounter this issue when trying to swipe or simply tapping on the screen. However, when I place buttons and perform the swipe actions using those buttons, I do not experience any issues. But if I initially perform the swipe manually by dragging, the animation gets disrupted and the swipe buttons no longer work.

https://github.com/alexbrillant/react-native-deck-swiper/assets/67295748/ee2bc609-df21-4b98-8e7e-cc0cf103ba32

(Please ignore the duplicate images in the last set of data. Focus on the names instead.)

My Code:

<View style={{flex: 1}}>
                <Swiper
                    useViewOverflow={Platform.OS === 'ios'}
                    // @ts-ignore
                    ref={swiper}
                    cards={data}
                    disableBottomSwipe={true}
                    disableTopSwipe={false}
                    cardStyle={{
                        top: 0,
                        left: 0,
                        bottom: 0,
                        right: 0,
                        width: 'auto',
                        height: 'auto'
                    }}
                    renderCard={(card) => {
                        return (
                            <View style={{flex: 1, margin: 10, marginVertical: 0, borderRadius: 10}}>
                                <Image source={{uri: card.image}} style={{width: windowWidth - 20, height: '100%', borderRadius: 10}} />
                                <View style={styles.userInfoContainer}>
                                    <Text style={styles.userName}>{card.name+", "+card.age}</Text>
                                </View>
                                <CardBackdrop />
                            </View>
                        )
                    }}
                    overlayLabels={{
                        bottom: {
                          title: 'BLEAH',
                          style: {
                            label: {
                              backgroundColor: 'black',
                              borderColor: 'black',
                              color: 'white',
                              borderWidth: 1
                            },
                            wrapper: {
                                flexDirection: 'column',
                                alignItems: 'center',
                                justifyContent: 'center'
                            }
                          }
                        },
                        left: {
                            title: 'NOPE',
                            style: {
                                label: {
                                backgroundColor: 'black',
                                borderColor: 'black',
                                color: 'white',
                                borderWidth: 1
                                },
                                wrapper: {
                                    flexDirection: 'column',
                                alignItems: 'flex-end',
                                justifyContent: 'flex-start',
                                marginTop: 30,
                                marginLeft: -30
                                }
                            }
                        },
                        right: {
                            title: 'LIKE',
                            style: {
                                label: {
                                  backgroundColor: 'black',
                                  borderColor: 'black',
                                  color: 'white',
                                  borderWidth: 1
                                },
                                wrapper: {
                                  flexDirection: 'column',
                                  alignItems: 'center',
                                  justifyContent: 'center',
                                  marginTop: 30,
                                  marginRight: 30
                                }
                              }
                            },
                        top: {
                            title: 'SUPER LIKE',
                            style: {
                                label: {
                                  backgroundColor: 'black',
                                  borderColor: 'black',
                                  color: 'white',
                                  borderWidth: 1
                                },
                                wrapper: {
                                  flexDirection: 'column',
                                  alignItems: 'center',
                                  justifyContent: 'center'
                                }
                            }
                        }
                    }}
                    animateOverlayLabelsOpacity
                    onSwipedLeft={() => onSwiped('left')}
                    onSwipedRight={() => onSwiped('right')}
                    onSwipedTop={() => onSwiped('top')}
                    onSwipedBottom={() => onSwiped('bottom')}
                    onSwipedAll={() => {console.log('onSwipedAll')}}
                    onSwiped={(cardIndex) => setCardIndex(cardIndex)}
                    backgroundColor={'white'}
                    cardIndex={cardIndex}
                    stackSize= {3}
                >

                </Swiper>
            </View>
KMuteteke commented 1 year ago

I am expeiencing the same thing!

IslamElswafy commented 1 year ago

i was facing the same problem but when i change the version of Expo in your project from "^49.0.0" to "^48.0.0", and did the same in react native form 0.72 to 0.71 it work

psuedoForce commented 1 year ago

I am experiencing the same thing. Subsequent swipes are not working on react-native-cli

omercandemir commented 1 year ago

I will test it in react-native version 0.71.11 soon and post the results here.

Lamonarch87 commented 1 year ago

Hi Guys,

this is the current resetPanAndScale function.

resetPanAndScale = () => {
    const {previousCardDefaultPositionX, previousCardDefaultPositionY} = this.props
    this.state.pan.setValue({ x: 0, y: 0 }) 
    this.state.previousCardX.setValue(previousCardDefaultPositionX)
    this.state.previousCardY.setValue(previousCardDefaultPositionY)
}

This is the working one.

resetPanAndScale = () => {
    const {previousCardDefaultPositionX, previousCardDefaultPositionY} = this.props
    this.state.pan.setValue({ x: 0, y: 0 })
    this.state.pan.setOffset({ x: 0, y: 0})
    this._animatedValueX = 0
    this._animatedValueY = 0
    this.state.previousCardX.setValue(previousCardDefaultPositionX)
    this.state.previousCardY.setValue(previousCardDefaultPositionY)
    this.state.pan.x.addListener(value => this._animatedValueX = value.value)
    this.state.pan.y.addListener(value => this._animatedValueY = value.value)
}

I found that after the swipe, the listener is unsubscribed even if no unmount was triggered.

mohitkale commented 1 year ago

Hi Guys,

this is the current resetPanAndScale function.

resetPanAndScale = () => {
    const {previousCardDefaultPositionX, previousCardDefaultPositionY} = this.props
    this.state.pan.setValue({ x: 0, y: 0 }) 
    this.state.previousCardX.setValue(previousCardDefaultPositionX)
    this.state.previousCardY.setValue(previousCardDefaultPositionY)
}

This is the working one.

resetPanAndScale = () => {
    const {previousCardDefaultPositionX, previousCardDefaultPositionY} = this.props
    this.state.pan.setValue({ x: 0, y: 0 })
    this.state.pan.setOffset({ x: 0, y: 0})
    this._animatedValueX = 0
    this._animatedValueY = 0
    this.state.previousCardX.setValue(previousCardDefaultPositionX)
    this.state.previousCardY.setValue(previousCardDefaultPositionY)
    this.state.pan.x.addListener(value => this._animatedValueX = value.value)
    this.state.pan.y.addListener(value => this._animatedValueY = value.value)
}

I found that after the swipe, the listener is unsubscribed even if no unmount was triggered.

Perfect @Lamonarch87 .... I would recommend you to fork the repo and create a PR so that the author can merge it

webraptor commented 1 year ago

fixed by https://github.com/webraptor/react-native-deck-swiper/pull/112#pullrequestreview-1553926364 version 2.0.15

a396901990 commented 1 year ago

Hi Guys,

this is the current resetPanAndScale function.

resetPanAndScale = () => {
    const {previousCardDefaultPositionX, previousCardDefaultPositionY} = this.props
    this.state.pan.setValue({ x: 0, y: 0 }) 
    this.state.previousCardX.setValue(previousCardDefaultPositionX)
    this.state.previousCardY.setValue(previousCardDefaultPositionY)
}

This is the working one.

resetPanAndScale = () => {
    const {previousCardDefaultPositionX, previousCardDefaultPositionY} = this.props
    this.state.pan.setValue({ x: 0, y: 0 })
    this.state.pan.setOffset({ x: 0, y: 0})
    this._animatedValueX = 0
    this._animatedValueY = 0
    this.state.previousCardX.setValue(previousCardDefaultPositionX)
    this.state.previousCardY.setValue(previousCardDefaultPositionY)
    this.state.pan.x.addListener(value => this._animatedValueX = value.value)
    this.state.pan.y.addListener(value => this._animatedValueY = value.value)
}

I found that after the swipe, the listener is unsubscribed even if no unmount was triggered.

still have this issue using this fix on 0.72.x

alex-paczeika commented 8 months ago

Hello, it's the same issue with 0.72.X. Can you please check?

https://github.com/alexbrillant/react-native-deck-swiper/assets/33178803/86965be6-fc34-4719-8705-1798cc0c6510

webraptor commented 8 months ago

Hello, it's the same issue with 0.72.X. Can you please check?

test_QUQOz4Wh.mp4

Based on the attached video the swiper works but you're changing the contents of the deck externally

flikQ commented 4 months ago

This appears to be happening for me also - on RN 0.73.8 & 2.0.16 of Deck Swiper