yuyakaido / CardStackView

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

onCardAppeared() not called first time when items are loaded #265

Open asifrpatel opened 5 years ago

asifrpatel commented 5 years ago

When items are loaded, then onCardAppeared() is not called for position 0.

szili9992 commented 5 years ago

I have the same problem. Can this be looked at?

robertBadamshin commented 5 years ago

This happened to me when I firstly passed empty list to adapter, and then passed not empty list. Now my code looks: if (items.isNotEmpty) { adapter.setItems(items) adapter.notifyDataSetChanged() }

dbof10 commented 4 years ago

is there any workaround?

dbof10 commented 4 years ago

my case I tried

override fun submitList(list: List<Swipe>?) {
        if (!firstCommit) {
            super.submitList(list) {
                notifyDataSetChanged()
            }
            firstCommit = true
        } else {
            super.submitList(list)
        }
    }

note that
val holder = vStackView.findViewHolderForAdapterPosition(position) holder is null in this particular case

TemMax commented 4 years ago

This happens because s.didStructureChange() returns false or getTopView() returns null. It returns false or null on some cases, for example: your adapter has empty data list and you try push new data with DiffUtil. In this case notifyDataSetChanged will not be called. For prevent this behavior add some check (for ex: YourAdapter#data.isEmpty()) before using DiffUtil and if your current adapter data is empty — use common way with notifyDataSetChanged instead of DiffUtil.

AnSuSh commented 2 years ago

my case I tried

override fun submitList(list: List<Swipe>?) {
        if (!firstCommit) {
            super.submitList(list) {
                notifyDataSetChanged()
            }
            firstCommit = true
        } else {
            super.submitList(list)
        }
    }

note that val holder = vStackView.findViewHolderForAdapterPosition(position) holder is null in this particular case

This helped me..Thanks..