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] CollectionView crashes on GridItemsLayout Horizontal #13105

Open davidortinau opened 3 years ago

davidortinau commented 3 years ago

Description

Vertical orientation works fine, but horizontal crashes both during hot reload, and upon rerun.

Unhandled Exception:
System.ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds
Parameter name: destinationArray
  at System.Array.Copy (System.Array sourceArray, System.Int32 sourceIndex, System.Array destinationArray, System.Int32 destinationIndex, System.Int32 length) [0x000cb] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System/Array.cs:600 
  at System.Array.CopyTo (System.Array array, System.Int32 index) [0x00017] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Array.cs:144 
  at Xamarin.Forms.Platform.iOS.GridViewLayout.LayoutAttributesForElementsInRect (CoreGraphics.CGRect rect) [0x000c6] in D:\agent\1\s\Xamarin.Forms.Platform.iOS\CollectionView\GridViewLayout.cs:134 
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],
<CollectionView
            Margin="15"
            x:Name="LayoutsCV"
            ItemsSource="{Binding XamarinAll}"
            IsGrouped="True" 
            SelectionMode="None">
            <CollectionView.ItemsLayout>
                <GridItemsLayout
                    Span="4"
                    HorizontalItemSpacing="10"
                    VerticalItemSpacing="10"
                    Orientation="Horizontal" />
            </CollectionView.ItemsLayout>
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Frame
                        HorizontalOptions="Center"
                        HeightRequest="60"
                        WidthRequest="220"
                        Padding="8"
                        CornerRadius="3"
                        BackgroundColor="White"
                        BorderColor="{Binding GroupIndex,
                        Converter={StaticResource IndexToColorConverter},
                        ConverterParameter='ThemePrimary;ThemeSecondary;NeutralTertiary'}"
                        Visual="Material">
                        <Grid ColumnDefinitions="64,*">
                            <Image Source="{Binding Icon}"
                                   HeightRequest="32"
                                   WidthRequest="32"
                                   VerticalOptions="Center"
                                   HorizontalOptions="Center"
                                   />
                            <Label
                                Grid.Column="1"
                                InputTransparent="true"
                                FontSize="14"
                                TextColor="{AppThemeBinding 
                                    Dark={StaticResource TextPrimaryColor_Dark},
                                    Light={StaticResource TextPrimaryColor_Light}}"
                                LineBreakMode="NoWrap"
                                VerticalOptions="Center"
                                Text="{Binding Title}"
                                d:Text="Something Else" />
                        </Grid>
                        <Frame.GestureRecognizers>
                            <TapGestureRecognizer
                                Command="{Binding SelectCommand,Source={RelativeSource AncestorType={x:Type local:IndexPageViewModel}}}"
                                CommandParameter="{Binding .}"
                                />
                        </Frame.GestureRecognizers>
                    </Frame>
                </DataTemplate>
            </CollectionView.ItemTemplate>
            <CollectionView.GroupHeaderTemplate>
                <DataTemplate>
                    <Label Text="{Binding Name}"
                           FontSize="18"
                           />
                </DataTemplate>
            </CollectionView.GroupHeaderTemplate>
        </CollectionView>

Basic Information

Environment

https://gist.github.com/davidortinau/75dfcee9bc8281af454ad890fda34de0

Screenshots

Vertical:

Simulator Screen Shot - iPad Pro (9 7-inch) - 2020-12-10 at 13 35 02

Horizontal:

Screen Shot 2020-12-10 at 1 35 28 PM

Reproduction Link

https://github.com/davidortinau/Xappy/blob/main/Xappy/Xappy/Content/ControlGallery/IndexPage.xaml#L30

GriffinMeyer commented 2 years ago

I'm currently running into this issue. Is there a workaround and/or ETA for when this might be fixed?