Skip to content

Commit 17aca8a

Browse files
committed
Fixed the ItemSpacing issue in CV2
1 parent e729e0e commit 17aca8a

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ protected override UICollectionViewLayout SelectLayout()
4444
NSCollectionLayoutDimension itemHeight = NSCollectionLayoutDimension.CreateFractionalHeight(1);
4545
NSCollectionLayoutDimension groupWidth = NSCollectionLayoutDimension.CreateFractionalWidth(1);
4646
NSCollectionLayoutDimension groupHeight = NSCollectionLayoutDimension.CreateFractionalHeight(1);
47-
nfloat itemSpacing = 0;
4847
NSCollectionLayoutGroup group = null;
4948

5049
var layout = new UICollectionViewCompositionalLayout((sectionIndex, environment) =>
@@ -91,8 +90,11 @@ protected override UICollectionViewLayout SelectLayout()
9190

9291
// Create our section layout
9392
var section = NSCollectionLayoutSection.Create(group: group);
94-
section.InterGroupSpacing = itemSpacing;
9593
section.OrthogonalScrollingBehavior = isHorizontal ? UICollectionLayoutSectionOrthogonalScrollingBehavior.GroupPagingCentered : UICollectionLayoutSectionOrthogonalScrollingBehavior.None;
94+
if (VirtualView.ItemsLayout is LinearItemsLayout linearItemsLayout)
95+
{
96+
section.InterGroupSpacing = (nfloat)linearItemsLayout.ItemSpacing;
97+
}
9698
section.VisibleItemsInvalidationHandler = (items, offset, env) =>
9799
{
98100
//This will allow us to SetPosition when we are scrolling the items

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@
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+
<!-- 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+
<CarouselView Margin="2,9,2,20"
1010
HeightRequest="180"
1111
Loop="False"
1212
PeekAreaInsets="20"
1313
VerticalOptions="End"
1414
HorizontalScrollBarVisibility="Never">
15-
<local:CarouselView1.ItemsSource>
15+
<CarouselView.ItemsSource>
1616
<x:Array Type="{x:Type x:String}">
1717
<x:String>Item1</x:String>
1818
<x:String>Item2</x:String>
1919
<x:String>Item3</x:String>
2020
</x:Array>
21-
</local:CarouselView1.ItemsSource>
22-
<local:CarouselView1.ItemsLayout>
21+
</CarouselView.ItemsSource>
22+
<CarouselView.ItemsLayout>
2323
<LinearItemsLayout ItemSpacing="5"
2424
Orientation="Horizontal"
2525
SnapPointsAlignment="Center"
2626
SnapPointsType="MandatorySingle"/>
27-
</local:CarouselView1.ItemsLayout>
28-
<local:CarouselView1.ItemTemplate>
27+
</CarouselView.ItemsLayout>
28+
<CarouselView.ItemTemplate>
2929
<DataTemplate
3030
x:DataType="{x:Null}">
3131
<Border BackgroundColor="Red"
@@ -103,7 +103,7 @@
103103
</Grid>
104104
</Border>
105105
</DataTemplate>
106-
</local:CarouselView1.ItemTemplate>
107-
</local:CarouselView1>
106+
</CarouselView.ItemTemplate>
107+
</CarouselView>
108108
</Grid>
109109
</ContentPage>

0 commit comments

Comments
 (0)