CollectionView refreshing in visually unattractive way RRS feed

  • Question

  • User394063 posted

    I'm working with an app that uses Xamarin iOS in combination with MvvmCross. MvvmCross wasn't updated for a long while by the people working on it before me, and with some things breaking on iOS 13 I have to update to a newer version to keep the app intact. However, since exactly MvvmCross 4.2.0 the CollectionViews are updating in a strange way that is visually very unappealing.

    On MvvmCross 4.1.0 and below the CollectionView refreshes the all the data visually instantly. Starting with MvvmCross 4.2.0 this doesn't happen anymore, but there is some sort of weird "caching" of CollectionView items happening. I've looked into the changes introduced in this version, but just can't get it back to how it used to be. Especially when the bound backing data in the ViewModel changes to a different count this kind of thing is even more noticeable. Since pictures explain this situation better:

    These pictures were taken off of a slowmotion video taken from the screen to capture what is happening.

    A little explanation: These are two separate CollectionViews. The upper "bar"-like CollectionView is the grouping collection. Each of the view cells in turn load new data into the item CollectionView below it. In this example we had the middle group open and are now switching to the items of the first group. As you can see the ViewCells of the middle group seem to be reused (and somehow rearranged in a different order) and arranged in the correct way first before replacing them with the correct data / versions. You can also see that one of the items of the target grouping is already loaded into one ViewCell. Before the update of MvvmCross this in between step didn't occur, going basically instantly (although probably some hundreds of milliseconds slower), which gives the whole thing a much cleaner look.

    I hope someone with MvvmCross knowledge knows what has changed here and how to revert it to the way it used to be. Since this seems to be a certain feature of iOS and thus also Xamarin iOS it would also be appreciated if someone could explain to me what is going on here. This is probably a feature of the iOS platform that I do not know about, since there seems to be a certain ViewCell caching strategy at play here.

    Edit: I forgot to add some more information: This happens regardless of the version of iOS, so it's 100% something that has changed within MvvmCross. 4.1.0 and below give the correct fluid transition on each iOS version, while 4.2.0 and above have the choppy transition on each iOS version.

    Thursday, July 9, 2020 1:28 PM

All replies

  • User394063 posted


    If this is the correct softlion that also worked on MvvmCross, I think this has to do with a change you made back in the days. Could you help me on the way? I looked at the changes you made in this version and I fixed this issue by adding an override in my CollectionViewSource:

    public override void CellDisplayingEnded(UICollectionView collectionView, UICollectionViewCell cell, NSIndexPath indexPath) { var bindable = cell as IMvxDataConsumer; if (bindable != null) bindable.DataContext = null; }

    However, now the refreshing of CollectionView is super slow compared to how it used to be in the pre-4.2.0 version. Is it possible that this have to do with the change of BindingContext? I tried registering the old one on the Mvx IoC, but it gives me binding issues from the get go.

    Thursday, July 9, 2020 7:13 PM
  • User2029 posted

    Hey I suggest you copy paste your question on slack, xamarinchat, #mvvmcross. I can’t remember changing anything in collectionviews.

    Thursday, July 9, 2020 7:39 PM
  • User394063 posted

    @softlion said: Hey I suggest you copy paste your question on slack, xamarinchat, #mvvmcross. I can’t remember changing anything in collectionviews.

    I actually fixed it, but I am still wondering why it had the issues it did before this and if I can fix it while not using legacy classes.

    I don't blame you for not remembering, since it's been years. And I wish the person working on this project before me would have kept MvvmCross up to date years ago and worked on this issue when it was still fresh, but we can't have it all unfortunately.

    It basically had to do with this pull request of yours from the 4.2.0 milestone:


    The change to the BaseMvxCollectionViewSource is the one that causes the "flickering" with reloaded ViewCells. I kind of do understand why this stops happening once I revert the change, since the ViewCells stop having the backing DataContext when they reload.

    This stopped the flickering, but the loading of the CollectionView got quite slow (it was very noticeable). I solved this by using the old MvxBindingContext instead of the newly introduced TaskBased one.

    So while things are solved now I still wonder why this was happening and if I can prevent the "flickering" somehow while using the default code by fixing some archaic way of doing things in my codebase.

    If you really don't remember or have no clue, that's alright. For now the issue is fixed for the short term.

    Edit: Whoops, linked the wrong pull request. Fixed.

    Friday, July 10, 2020 7:17 AM