Xamarin.Forms icon indicating copy to clipboard operation
Xamarin.Forms copied to clipboard

[Bug] [UWP] Regression bug on CollectionView included in FlyoutPage.Detail

Open DDHSchmidt opened this issue 3 years ago • 7 comments

Description

Service Release 9 (5.0.0.2337) introduced a regression that leads to an exception/crash on UWP whenever we revisit a view that contains a CollectionView. We use a FlyoutPage in our mainpage and whenever we present a FlyoutPage.Detail with a CollectionView for the second time, it will crash with a stacktrace containing the lines

System.NotImplementedException: The layout is not implemented
   at Xamarin.Forms.Platform.UWP.StructuredItemsViewRenderer`1.SelectListViewBase()
   at Xamarin.Forms.Platform.UWP.ItemsViewRenderer`1.SetUpNewElement(ItemsView newElement)
   at Xamarin.Forms.Platform.UWP.SelectableItemsViewRenderer`1.SetUpNewElement(ItemsView newElement)
   at Xamarin.Forms.Platform.UWP.ItemsViewRenderer`1.OnElementChanged(ElementChangedEventArgs`1 args)
   at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.SetElement

Downgrading to Service Release 8 (5.0.0.2291) eliminates the crash.

We suspect the regression was introduced with PullRequest 14780 since it includes a check for StructuredItemsView

Steps to Reproduce

  1. Open a Flyout page, containing a CollectionView on UWP
  2. Navigate to another Detail view
  3. Revisit the first view

Expected Behavior

FlyoutPage renders the content, including all CollectionViews

Actual Behavior

Crash with "System.NotImplementedException: The layout is not implemented"

Basic Information

  • Version with issue: 5.0.0.2337
  • Last known good version: 5.0.0.2291
  • Platform Target Frameworks:
    • UWP: 16299

Reproduction Link

Please see the attached reproduction project UWPCollectionViewNavigationCrash.zip

Workaround

Downgrade to Service Release 8 (5.0.0.2291)

DDHSchmidt avatar May 06 '22 14:05 DDHSchmidt

@YZahringer I know it has been a while, but still wanted to ping you to see if you maybe have an idea on this one :)

jfversluis avatar May 10 '22 13:05 jfversluis

@jfversluis I think the regression is caused by the ItemsLayout null assignation on https://github.com/xamarin/Xamarin.Forms/pull/14780/files#r734946106.

As commented, I had my doubts in the past about this, but the memory leak persisted otherwise.

A possible way to solve this regression and avoid the memory leak, would be to assign a new LinearItemsLayout or GridItemsLayout instead of null.

YZahringer avatar May 10 '22 13:05 YZahringer

So... can this be tested or will we have to remain on the old version forever?

DDHSchmidt avatar Jun 22 '22 14:06 DDHSchmidt

@jfversluis & @YZahringer I'm more than willing to test anything you throw at me. If there is a way to to bundle this change in a NuGet package I'll gladly try it out in our apps.

DDHSchmidt avatar Jul 02 '22 08:07 DDHSchmidt

Any ETA for fix? I am using a workaround of assigning ItemsLayout with a new LinearItemsLayout on revisiting the view.

shajiraghav avatar Jul 18 '22 17:07 shajiraghav

LinearItemsLayout

@shajiraghav Do you have any example code I could reference for your work around? I'm having this issue in a production project and would like to update to the latest build, but can't because of this issue on UWP

mrgenixus avatar Apr 13 '23 15:04 mrgenixus

Hello, I am having this issue when the CollectionView when I have the collectionview inside a scroll view.

To make my apps responsive I usually put a ScrollView in my content pages, and put a grid in the scroll view.

Then I use this pattern I picked up somewhere on the internet:

        void UpdateLayout()
        {

            if (width < CUTOFF_WIDTH && height < CUTOFF_HEIGHT)
            {
                this.Content = scrollView;
                scrollView.Content = mainGrid;
                SetupScrollingPortraitLayout();
            }
            else if ( width >= CUTOFF_WIDTH && height < CUTOFF_HEIGHT)
            {
                this.Content = scrollView;
                scrollView.Content = mainGrid;
                SetupScrollingLandscapeLayout();
            }
            else if (width < CUTOFF_WIDTH && height >= CUTOFF_HEIGHT)
            {
                scrollView.Content = null;
                this.Content = mainGrid;
                SetupPortraitLayout();
            }
            else // width >= CUTOFF_WIDTH && height >= CUTOFF_HEIGHT
            {
                scrollView.Content = null;
                this.Content = mainGrid;
                SetupLandscapeLayout();
            }

        }

I call the above in OnSizeAllocated whenever the page size has changed. If I get rid of this craziness and just leave the scroll view at all times, the crash goes away. I just have the scroll view for very small screen sizes like on desktop if the user shrinks the window on a small laptop screen.

melvyniandrag avatar Nov 03 '23 21:11 melvyniandrag