How can I disable swipe next card without my control in this library?

55 views Asked by At

I'm just using this cardStackView library to make app like tinder swipe. https://github.com/yuyakaido/CardStackView I just want to show Question dialog if user want to swipe right that means like profile. I can achieve this easily when user click like button. But when user make swipe right I can not do this perfectly. It swipe automatically. How can achieve this?

I tried make treshold higher and can realize when need to show dialog before swipe. But when fastly swipe card I can not stop swipe next card.

private fun setCardStackView() {
    val cardStackLayoutManager = CardStackLayoutManager(requireContext(), object : CardStackListener {
        override fun onCardDragging(direction: Direction?, ratio: Float) {
            when (direction) {
                Direction.Right -> {
                    if (ratio >= 0.6f && !viewModel.isQuestionDialogOpen){
                        viewModel.isQuestionDialogOpen = true
                        viewModel.hasStartedLikeSwipeProcess = true
                        openQuestionDialog()
                    }
                }

                Direction.Left -> {
                    if (ratio >= 0.6f){
                        userProfileList[currentCardIndex].isDisliked = true
                        userProfileList[currentCardIndex].isLiked = false
                        binding.cardStackView.swipe()
                    }
                }

                else -> {}
            }
        }

        override fun onCardSwiped(direction: Direction?) {
            when (direction) {
                Direction.Right -> {}
                Direction.Left -> {}
                else -> {}
            }
        }

        override fun onCardRewound() {}

        override fun onCardCanceled() {
            if (viewModel.hasStartedLikeSwipeProcess) {
                viewModel.hasStartedLikeSwipeProcess = false
                userProfileList[currentCardIndex].isLiked = true
                userProfileList[currentCardIndex].isDisliked = false
                cardStackAdapter.notifyItemChanged(currentCardIndex)
            }
        }

        override fun onCardAppeared(view: View?, position: Int) {
            currentCardIndex = position
        }

        override fun onCardDisappeared(view: View?, position: Int) { }
    })
    cardStackLayoutManager.setStackFrom(StackFrom.None)
    cardStackLayoutManager.setDirections(Direction.HORIZONTAL)
    cardStackLayoutManager.setSwipeableMethod(SwipeableMethod.AutomaticAndManual)
    cardStackLayoutManager.setSwipeThreshold(0.8f)
    binding.cardStackView.layoutManager = cardStackLayoutManager
    binding.cardStackView.adapter = cardStackAdapter
    cardStackAdapter.submitList(userProfileList)
    }

Adapter.

class MainProfilePreviewAdapter(
    private val onClickProfileAction: ((CardAction, adapterPosition: Int) -> Unit),
    private val onClickProfile: ((user: UserCard, adapterPosition: Int) -> Unit)
) : BaseListAdapter<UserCard>(
    itemsSame = { old, new -> old.id == new.id },
    contentsSame = { old, new -> old.id == new.id }
) {
    override fun onCreateViewHolder(
        parent: ViewGroup,
        inflater: LayoutInflater,
        viewType: Int
    ): RecyclerView.ViewHolder {
        return MainProfilePreviewViewHolder(parent, inflater, onClickProfileAction, onClickProfile)
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        when (holder) {
            is MainProfilePreviewViewHolder -> {
                holder.bind(getItem(position))
            }
        }
    }

}
0

There are 0 answers