Skip to content

Commit 44256ba

Browse files
Ahamed-AliPureWeen
authored andcommitted
[iOS] Fix for CarouselView ItemSpacing property in ItemsLayout not working with CV2 (#27056)
* Fixed the ItemSpacing issue in CV2 * reenabled the test * changed the fix based on conflicts file * Optimized the fix in the LayoutFactory2
1 parent 7e7eab4 commit 44256ba

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ public static UICollectionViewLayout CreateCarouselLayout(
272272
NSCollectionLayoutDimension itemHeight = NSCollectionLayoutDimension.CreateFractionalHeight(1);
273273
NSCollectionLayoutDimension groupWidth = NSCollectionLayoutDimension.CreateFractionalWidth(1);
274274
NSCollectionLayoutDimension groupHeight = NSCollectionLayoutDimension.CreateFractionalHeight(1);
275-
nfloat itemSpacing = 0;
276275
NSCollectionLayoutGroup group = null;
277276

278277
var layout = new UICollectionViewCompositionalLayout((sectionIndex, environment) =>
@@ -325,7 +324,10 @@ public static UICollectionViewLayout CreateCarouselLayout(
325324
}
326325

327326
var section = NSCollectionLayoutSection.Create(group: group);
328-
section.InterGroupSpacing = itemSpacing;
327+
if (itemsView.ItemsLayout is LinearItemsLayout linearItemsLayout)
328+
{
329+
section.InterGroupSpacing = (nfloat)linearItemsLayout.ItemSpacing;
330+
}
329331
section.OrthogonalScrollingBehavior = isHorizontal
330332
? UICollectionLayoutSectionOrthogonalScrollingBehavior.GroupPagingCentered
331333
: UICollectionLayoutSectionOrthogonalScrollingBehavior.None;

src/Controls/tests/TestCases.HostApp/Issues/Issue25192.xaml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,26 @@
44
xmlns:local="clr-namespace:Maui.Controls.Sample"
55
x:Class="Maui.Controls.Sample.Issues.Issue25192">
66
<Grid>
7-
<!-- This functionality failed in CarouselView2. Reference: https://github.com/dotnet/maui/issues/27025 -->
8-
<!-- TODO: Replace CarouselView1 with CarouselView once the issues mentioned in the GitHub issue are resolved. -->
9-
<local:CarouselView1 Margin="2,9,2,20"
7+
<CarouselView Margin="2,9,2,20"
108
HeightRequest="180"
119
Loop="False"
1210
PeekAreaInsets="20"
1311
VerticalOptions="End"
1412
HorizontalScrollBarVisibility="Never">
15-
<local:CarouselView1.ItemsSource>
13+
<CarouselView.ItemsSource>
1614
<x:Array Type="{x:Type x:String}">
1715
<x:String>Item1</x:String>
1816
<x:String>Item2</x:String>
1917
<x:String>Item3</x:String>
2018
</x:Array>
21-
</local:CarouselView1.ItemsSource>
22-
<local:CarouselView1.ItemsLayout>
19+
</CarouselView.ItemsSource>
20+
<CarouselView.ItemsLayout>
2321
<LinearItemsLayout ItemSpacing="5"
2422
Orientation="Horizontal"
2523
SnapPointsAlignment="Center"
2624
SnapPointsType="MandatorySingle"/>
27-
</local:CarouselView1.ItemsLayout>
28-
<local:CarouselView1.ItemTemplate>
25+
</CarouselView.ItemsLayout>
26+
<CarouselView.ItemTemplate>
2927
<DataTemplate
3028
x:DataType="{x:Null}">
3129
<Border BackgroundColor="Red"
@@ -103,7 +101,7 @@
103101
</Grid>
104102
</Border>
105103
</DataTemplate>
106-
</local:CarouselView1.ItemTemplate>
107-
</local:CarouselView1>
104+
</CarouselView.ItemTemplate>
105+
</CarouselView>
108106
</Grid>
109107
</ContentPage>

0 commit comments

Comments
 (0)