xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] SKCanvas images not rendering correctly in CollectionView #11064

Closed Stuart88 closed 4 years ago

Stuart88 commented 4 years ago

Description

SKCanvas objects render incorrectly in the last couple of cells of a larger CollectionView

The images are LaTex equations created via the CSharpMath Latex library, which utilises SkiaSharp to turn LaTex equation string into an SKCanvasView object.

So SKCanvasView is what the CollectionView is having problems with, I believe.

If I use a ListView instead, the issue does not occur.

Steps to Reproduce

  1. Bind CollectionView to large list of items where one of the bindings is to an SKCanvasView (or more specifically a MathView from the CSharpMath.Forms library)
  2. View page containing the list of items
  3. Scroll to end of list

Expected Behavior

Items rendered correctly

Actual Behavior

Last item(s) of list show repeat of first item(s)

Information

Screenshots

image

image

image

Reproduction Link

The following branch can be built to see the issue in action

https://github.com/Stuart88/pure-physicist/tree/wip/collection-view-problem

To locate the issue in the app (Android), navigate to: Menu -> Topics -> Classical Mechanics -> Equations

Relevant files:

XAML page containing the CollectionView https://github.com/Stuart88/pure-physicist/blob/wip/collection-view-problem/PurePhysicist/PurePhysicist/Views/Topics/EquationsViewBase.xaml

Code-behind https://github.com/Stuart88/pure-physicist/blob/wip/collection-view-problem/PurePhysicist/PurePhysicist/Views/Topics/EquationsViewBase.xaml.cs

Workaround

Currently using ListView instead

samhouts commented 4 years ago

First, nice app!

Second, I strongly suspect you're hitting the same problem that is described here: https://github.com/xamarin/Xamarin.Forms/issues/9200#issuecomment-643822589

ListView is not as good as CollectionView is at virtualization. That's good because your app will be much more responsive. The tradeoff is that you need to be explicit about the bindings for complex templates.