Cardview: Problems with view when updating collection

Created on 13 May 2018  路  14Comments  路  Source: AndreiMisiukevich/CardView

Hi,
I think there is some bug in View handling or caching. I have this situation:CarouselView with Items bound to ObservableCollection. In ItemTemplate there is simple Grid with Image and Label. I use Label.GestureRecognizer to remove current Item. When I remove item from ObservableCollection CurrentIndex is reset to 0, it can be easily workarounded by "holding" current index and then setting it back. But when CarouselView is on first item(i.e. CurrentIndex=0) and this first item is removed view stays the same. Image(whole Item, to be precise) is not changed until I swipe to next and then back. I tried IsViewCacheEnabled="False" without any effect. I understand Carousel only refresh when CurrentIndex is changed but in this particular situation I need to trigger reload(removing and setting back Binding context makes things only worse, beacause image than stays on top of carousel, and other images slide under). Issue is not limited to Image, I tried replacing image with Label and issue persist

I cannot provide repro solution at the moment , but simply removing first element from ObservableCollection bound to Items after page is loaded via button or something similar should produce described result.

bug resolved

All 14 comments

Thanks for feedback
I will dive into the issue

But if you add sample, I will appreciate

I managed to put together quick repo which should help reproducing (and hopefully solve) this issue. Issue is in my case present in linked repository. Testing was done on Samsung Galaxy S9 running Android 8.
Link to the repository https://github.com/Pomezny/CarouselViewIssue26Repro
Decription:

  • Simple app with CarouselView on MainPage and log of actions done below. One remove button is in every ItemTemplate, it removes items by direct reference to ItemViewModel, other remove button is removing item via CurrentIndex. Add button adds new item to Items, with current time as AnotherCaption(to distinguish it from other items). Restore list button clears Items and fill it again with starting sample data
  • When you are at first item, try clicking "Remove me!", item is removed as indicated in log, but still present on page. Now, when you swipe to next item, you will see item nr.3, when you swipe back you will see item nr2. Correct behaviour should be that after removing nr.1, item nr.2 should be shown on page.
  • If you remove all items last one is still visible, when you add new item, nothing happens, since you still cannot swipe to next item to "repair" what is shown, finally when you add another one, you can swipe and get rid of the "stuck" item which should be long gone.
  • I even managed to reproduce situation where items are overlapping after clearing Items. (Mentioned in previous comment as removing and settign back Binding context). Start app, swipe to second item, and then click "Restore list", in my case CarouselView pans to first item, but second item(from previous collection) is laid over the first one, It can be seen in Caption, but not AnotherCaption, since it has background.
  • When clicking button in CarouselView, its not sometimes registred by button, I suspect that Carousel is stealing event in hope of swiping, in this case you can sometimes see that all text "blinks". With pictures it looks awful, but I suppose its not core of this issue and I think I can solve it with swipe threshold.

If you need any further assistance or my description is not precise or understandable enough just comment this issue, I will try to respond as soon as possible.

I will investigate it ) tomorrow, maybe

@Pomezny
Martin, one more question from me..

Does this bug occur on android only ? Or on iOS too? Or you haven't tested yet?

@AndreiMisiukevich I will test reproduction repository in few hours on iOS and report back to you.

@Pomezny I've already tested it
Yes, this bug occurs on iOS too)

https://github.com/AndreiMisiukevich/CardView/blob/master/PanCardView/CardsView.cs#L1084-L1110

This method is the reason of our "pain" ))
I need extra time for refactoring it, because it looks like invalid

I extended the sample (first button is buttons list) - http://prntscr.com/jhnzw1
Could you pls validate my fix?

Sample looks awesome, thanks. Although I will create PR since there are minor bugs in sample(typos I guess). I will try to hotwire this fixed version to my app to further verify expected behaviour. Will reply soon.

@Pomezny nice) I'm waiting your PR

By the way, if you enjoy this plugin, please, set "STAR" on the project here)

@Pomezny Don't forget to give me feedback) I will create new version

@AndreiMisiukevich Hi, I tested your fixes and they indeed seem to work on my app where I discovered them. The flickering after clicking item still persist, but its not crucial at the moment. Can you please publish corrected NuGet?
I will try to dig deeper to the flickering issue soon if I find some time for it and eventally open a new issue.
Thanks for your awesome work!

@Pomezny okay, i will publish it today's evening

1.4.2 have been published
It will be available soon

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stealthcold picture stealthcold  路  6Comments

morhung picture morhung  路  7Comments

LeoJHarris picture LeoJHarris  路  3Comments

LuisM000 picture LuisM000  路  3Comments

EldinHb picture EldinHb  路  8Comments