Skip to content

Commit 0ad7670

Browse files
committed
Fixed the ItemSpacing issue in CV2
1 parent ac01bde commit 0ad7670

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ protected override UICollectionViewLayout SelectLayout()
4545
NSCollectionLayoutDimension itemHeight = NSCollectionLayoutDimension.CreateFractionalHeight(1);
4646
NSCollectionLayoutDimension groupWidth = NSCollectionLayoutDimension.CreateFractionalWidth(1);
4747
NSCollectionLayoutDimension groupHeight = NSCollectionLayoutDimension.CreateFractionalHeight(1);
48-
nfloat itemSpacing = 0;
4948
NSCollectionLayoutGroup group = null;
5049

5150
var layout = new UICollectionViewCompositionalLayout((sectionIndex, environment) =>
@@ -92,8 +91,11 @@ protected override UICollectionViewLayout SelectLayout()
9291

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

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

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
33
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:Maui.Controls.Sample"
45
x:Class="Maui.Controls.Sample.Issues.Issue25192">
56
<Grid>
6-
<CarouselView Margin="2,9,2,20"
7-
HeightRequest="180"
8-
Loop="False"
9-
PeekAreaInsets="20"
10-
VerticalOptions="End"
11-
HorizontalScrollBarVisibility="Never">
12-
<CarouselView.ItemsSource>
7+
<local:CarouselView2 Margin="2,9,2,20"
8+
HeightRequest="180"
9+
Loop="False"
10+
PeekAreaInsets="20"
11+
VerticalOptions="End"
12+
HorizontalScrollBarVisibility="Never">
13+
<local:CarouselView2.ItemsSource>
1314
<x:Array Type="{x:Type x:String}">
1415
<x:String>Item1</x:String>
1516
<x:String>Item2</x:String>
1617
<x:String>Item3</x:String>
1718
</x:Array>
18-
</CarouselView.ItemsSource>
19-
<CarouselView.ItemsLayout>
19+
</local:CarouselView2.ItemsSource>
20+
<local:CarouselView2.ItemsLayout>
2021
<LinearItemsLayout ItemSpacing="5"
2122
Orientation="Horizontal"
2223
SnapPointsAlignment="Center"
2324
SnapPointsType="MandatorySingle"/>
24-
</CarouselView.ItemsLayout>
25-
<CarouselView.ItemTemplate>
25+
</local:CarouselView2.ItemsLayout>
26+
<local:CarouselView2.ItemTemplate>
2627
<DataTemplate
2728
x:DataType="{x:Null}">
2829
<Border BackgroundColor="Red"
@@ -100,7 +101,7 @@
100101
</Grid>
101102
</Border>
102103
</DataTemplate>
103-
</CarouselView.ItemTemplate>
104-
</CarouselView>
104+
</local:CarouselView2.ItemTemplate>
105+
</local:CarouselView2>
105106
</Grid>
106107
</ContentPage>

0 commit comments

Comments
 (0)