yuyakaido / CardStackView

📱Tinder like swipeable card view for Android
Apache License 2.0
2.34k stars 443 forks source link

Multiple automatic swipes not working #373

Closed CyprienRicque closed 1 year ago

CyprienRicque commented 1 year ago

Hello, I would like to swipe the 3 first cards one after the other as soon as they appear.

I have tried to implement it like this:

    override fun onCardAppeared(view: View, position: Int) {
        val textView = view.findViewById<TextView>(R.id.item_name)
        Log.d("CardStackView", "onCardAppeared: ($position) ${textView.text}")

        if (position < 3) {
            binding.likeButtonHome.performClick()
        }
    }

but it only works for the very first card, then it stops.

Note that the like button is properly triggered, but nothing happen when binding.CardStackView.swipe() is called. Also, the like button works fine when I click on it manually.

        val like = view.findViewById<View>(R.id.like_button_home)
        like.setOnClickListener {
            Log.d(TAG, "like button pressed")
            val setting = SwipeAnimationSetting.Builder()
                .setDirection(Direction.Right)
                .setDuration(Duration.Normal.duration)
                .setInterpolator(AccelerateInterpolator())
                .build()
            manager.setSwipeAnimationSetting(setting)
            binding.CardStackView.swipe()
        }

If anyone has an idea of what I'm doing wrong, any help is welcome :blush:

CyprienRicque commented 1 year ago

I had to use view.post

jtplartisan commented 5 months ago

Hi @CyprienRicque

Could please share how you got swipe() to work, I'm also stuck at this it just won't work