Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[iOS] Change how ItemsViewController.CheckEmptySource checks for item size #15289

Merged
merged 3 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Xamarin.Forms.Controls.Issues.Issue15287"
Title="Issue 15287">
<CollectionView ItemsSource="{Binding Items}" x:Name="MainCollection">
<CollectionView.ItemsLayout>
<GridItemsLayout Span="2" Orientation="Vertical" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="200" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<CarouselView Loop="False" ItemsSource="{Binding Images}" x:Name="Carousel">
<CarouselView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding .}" Aspect="AspectFill"/>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
<Label Text="{Binding Position, Source={x:Reference Carousel}}" Grid.Row="1"/>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Collections.Generic;
using System.Linq;
using Xamarin.Forms;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Shapes;

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 15287, "[Bug] [iOS] Changing CollectionView.ItemSizingStrategy that contains a CarouselView causes the CarouselView to size its cells incorrectly.", PlatformAffected.iOS)]
public partial class Issue15287 : ContentPage
{
public Issue15287()
{
#if APP
InitializeComponent();
#endif
BindingContext = new ViewModel();
}

protected override void OnAppearing()
{
base.OnAppearing();
#if APP
MainCollection.ItemSizingStrategy = ItemSizingStrategy.MeasureFirstItem;
#endif
}

public class ViewModel
{
public List<Item> Items { get; private set; }

public ViewModel()
{
Items = Enumerable.Range(0, 30).Select(x => new Item()).ToList();
}
}

public class Item
{
public IList<string> Images { get; } = new[]
{
"cover1.jpg",
"oasis.jpg",
"photo.jpg",
"Vegetables.jpg",
"Fruits.jpg",
"FlowerBuds.jpg",
"Legumes.jpg"
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,9 @@
<DependentUpon>MyCollectionView.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue15287.xaml.cs">
<DependentUpon>Issue15287.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
Expand Down Expand Up @@ -2417,6 +2420,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue15287.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla27417Xaml.xaml">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void CheckForEmptySource()
// If we're going from empty to having stuff, it's possible that we've never actually measured
// a prototype cell and our itemSize or estimatedItemSize are wrong/unset
// So trigger a constraint update; if we need a measurement, that will make it happen
ItemsViewLayout.ConstrainTo(CollectionView.Bounds.Size);
ConstrainToItemsView();
}
}

Expand Down