Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Fix for CarouselView ItemSpacing property in ItemsLayout not working with CV2 #27056

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Expand Up @@ -45,7 +45,6 @@ protected override UICollectionViewLayout SelectLayout()
NSCollectionLayoutDimension itemHeight = NSCollectionLayoutDimension.CreateFractionalHeight(1);
NSCollectionLayoutDimension groupWidth = NSCollectionLayoutDimension.CreateFractionalWidth(1);
NSCollectionLayoutDimension groupHeight = NSCollectionLayoutDimension.CreateFractionalHeight(1);
nfloat itemSpacing = 0;

var layout = new UICollectionViewCompositionalLayout((sectionIndex, environment) =>
{
Expand Down Expand Up @@ -83,7 +82,10 @@ protected override UICollectionViewLayout SelectLayout()

// Create our section layout
var section = NSCollectionLayoutSection.Create(group: group);
section.InterGroupSpacing = itemSpacing;
if (VirtualView.ItemsLayout is LinearItemsLayout linearItemsLayout)
jsuarezruiz marked this conversation as resolved.
Show resolved Hide resolved
{
section.InterGroupSpacing = (nfloat)linearItemsLayout.ItemSpacing;
}
section.OrthogonalScrollingBehavior = UICollectionLayoutSectionOrthogonalScrollingBehavior.GroupPagingCentered;
section.VisibleItemsInvalidationHandler = (items, offset, env) =>
{
Expand Down
17 changes: 9 additions & 8 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25192.xaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Maui.Controls.Sample"
x:Class="Maui.Controls.Sample.Issues.Issue25192">
<Grid>
<CarouselView Margin="2,9,2,20"
<local:CarouselView2 Margin="2,9,2,20"
HeightRequest="180"
Loop="False"
PeekAreaInsets="20"
VerticalOptions="End">
<CarouselView.ItemsSource>
<local:CarouselView2.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Item1</x:String>
<x:String>Item2</x:String>
<x:String>Item3</x:String>
</x:Array>
</CarouselView.ItemsSource>
<CarouselView.ItemsLayout>
</local:CarouselView2.ItemsSource>
<local:CarouselView2.ItemsLayout>
<LinearItemsLayout ItemSpacing="5"
Orientation="Horizontal"
SnapPointsAlignment="Center"
SnapPointsType="MandatorySingle"/>
</CarouselView.ItemsLayout>
<CarouselView.ItemTemplate>
</local:CarouselView2.ItemsLayout>
<local:CarouselView2.ItemTemplate>
<DataTemplate
x:DataType="{x:Null}">
<Border BackgroundColor="Red"
Expand Down Expand Up @@ -99,7 +100,7 @@
</Grid>
</Border>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
</local:CarouselView2.ItemTemplate>
</local:CarouselView2>
</Grid>
</ContentPage>
Loading